使用Unwind segue UITextField传递数据



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

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

我可以将数据从视图1传递到视图2:NSString中存储的URL显示在Text字段中。

现在,我想用视图2中的Text字段修改这个URL,并修改视图1中的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);}

ModifyShop:

- (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

错误是说您正在绑定Reports实例上的imageButtonURL,而不是您认为的目标视图控制器Shop。看来您的展开将转到错误的控制器。你一定是把放卷段挂错了。你说你有两个视图(实际上是视图控制器),但你的应用程序中也必须有一个Reports类。

最新更新