PrepareForSegue方法崩溃app iOS

时间:2016-02-18 13:02:08

标签: ios objective-c uiviewcontroller segue pushviewcontroller

我有一个UIButton,当我点击它时,推送另一个视图控制器,但它崩溃了 textViewController.message = self.selectedMessage;,错误设置消息。

这是我的按钮,其代码和方法崩溃:

- (IBAction)image:(id)sender {

   [self performSegueWithIdentifier:@"image" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showLogin"]) {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    } else {
        [segue.identifier isEqualToString:@"showImage"];
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
        ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
        imageViewController.message = self.selectedMessage;
    }
}

如何修复PrepareForSegue方法,以便在按下按钮时可以转到下一个VC。我放了异常断点,它在imageViewController.message = self.selectedMessage;崩溃了。当我评论该行时一切正常。

2 个答案:

答案 0 :(得分:0)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showLogin"]) {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    } else {
        ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
        [imageViewController setHidesBottomBarWhenPushed:YES];
        imageViewController.message = self.selectedMessage;
    }
}

试试这个。

答案 1 :(得分:0)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showLogin"]) {
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    } else if ([segue.identifier isEqualToString:@"showImage"]){
        [segue.destinationViewController setHidesBottomBarWhenPushed:YES];
        ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
        imageViewController.message = self.selectedMessage;
    }
}

必须将其更改为此才能使其正常工作

Accounts