【问题标题】:Passing data with Unwind segue UITextField使用 Unwind segue UITextField 传递数据
【发布时间】:2015-05-24 03:11:24
【问题描述】:

我有两种观点: View1 (Shop) : 存放在 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

【问题讨论】:

    标签: ios objective-c uitextfield pass-data unwind-segue


    【解决方案1】:

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

    【讨论】:

    • 是的,我有另一个视图“报告”,但我在哪里可以更改它?
    • @Viny76,您需要删除 unwind segue,并将其重新制作为正确的控制器。您是否还有一个方法,prepareForUnwind:,在 Reports 中?如果是这样,你应该重命名它,这样你就不会在两个不同的控制器中有两个同名的方法。
    • 感谢您的回复,是的,我有两个 prepareForUnwind,一个在 Reports 中,一个在 Shop 中。我如何指定我想要什么?
    • @Viny76,你像我说的那样重命名其中一个。这样,当你进行 segue 时,你会看到两个不同的选择返回到哪里,你可以选择正确的一个。
    • 是的,它现在非常适合 Unwind segue,它将我的 self.imageButtonURL 从 view2 更改为 UIText 字段。但我希望永远保存这个 URL 文本。我怎样才能做到这一点?
    猜你喜欢
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-29
    • 2016-12-20
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    相关资源
    最近更新 更多