' - [UINavigationController setLanguage:]:无法识别的选择器发送到实例0x7f8fba7df4e0'

时间:2015-03-10 19:13:24

标签: ios objective-c iphone xcode uitableview

几个小时前,在更新我的XCode之后,这段代码没有给我带来任何问题 我的XCode和删除第三方框架,它突然给我上面的例外。我非常困惑,因为我认为当时和现在之间没有任何改变,除了更新我的XCode之外还可能导致问题。任何人都可以看到问题吗?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

/*We check to make sure the segue corresponds to segue we created when a cell is selected*/
if ([[segue identifier] isEqualToString:@"show"]) {

   /*Get a pointer to the selected row*/
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    /*Get a pointer to the ViewController we will segue to*/
    ViewController *viewController = segue.destinationViewController;

    /*Pass the dialect and code back to the ViewController*/
   viewController.language = self.languages.allKeys[indexPath.row];
    viewController.code = [self.languages objectForKey:viewController.language];

  }
}

具体来说,以下两行导致异常:

viewController.language = self.languages.allKeys[indexPath.row];
viewController.code = [self.languages objectForKey:viewController.language];

1 个答案:

答案 0 :(得分:4)

您的segue的目标控制器是UINavigationController,您的视图控制器很可能是该导航控制器的顶视图控制器。你可能想要:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    /*We check to make sure the segue corresponds to segue we created when a cell is selected*/
    if ([[segue identifier] isEqualToString:@"show"]) {

    /*Get a pointer to the selected row*/
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    UINavigationController *navController = segue.destinationViewController

    /*Get a pointer to the ViewController we will segue to*/
    ViewController *viewController = navController.topViewController;

    /*Pass the dialect and code back to the ViewController*/
    viewController.language = self.languages.allKeys[indexPath.row];
    viewController.code = [self.languages objectForKey:viewController.language];
  }
}