0

我有两个视图: View1(商店):存放在 NSString 中用于显示图像的 URL。

View2 (ModifyShop) :带有来自 view1 的 URL 的文本字段。

我可以将数据从 view1 传递到 view2 :存放在 NSString 中的 URL 出现在 Text 字段中。

现在我想用 view2 中的 Text 字段修改这个 URL,并修改 view1 中的 NSString。我怎样才能做到这一点?

这是我的代码:

店铺:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.modifyButton setHidden:YES];
    dispatch_async(dispatch_get_global_queue(0,0), ^{
        self.imageButtonURL = @"http://bundoransurfshop.com/wp-content/uploads/2015/02/72-torq-pink.jpg";
        imageButtonData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:self.imageButtonURL]];
        if ( imageButtonData == nil )
            return;
        dispatch_async(dispatch_get_main_queue(), ^{
            self.imageButton.imageView.image = [UIImage imageWithData: imageButtonData];
        });
    });
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"modifyShop"]) {
        ShopModify *viewcontroller = (ShopModify *)segue.destinationViewController;
    viewcontroller.imageButtonURL = self.imageButtonURL;      }
}

-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
    NSLog(@"%@", self.imageButtonURL);}

修改商店:

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.photoURL.text = [NSString stringWithFormat:@"%@", self.imageButtonURL];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        Shop *viewcontroller = (Shop *)segue.destinationViewController;
        viewcontroller.imageButtonURL = self.photoURL.text;
}

这使我的应用程序崩溃:

[Reports setImageButtonURL:]: unrecognized selector sent to instance
4

1 回答 1

1

错误是说您要在报告实例上设置 imageButtonURL,而不是在您认为目标视图控制器的 Shop 上设置。看来您的放松会转到错误的控制器。您一定是错误地连接了 unwind segue。您说您有 2 个视图(实际上是视图控制器),但您的应用程序中还必须有一个 Reports 类。

于 2015-03-20T16:23:29.940 回答