由于核心数据传输转移导致应用程序崩溃

时间:2014-07-08 03:29:36

标签: ios objective-c uitableview core-data

我正在从Core Data模型将内容加载到UITableView控制器中,并希望能够按下数据点并让它打开编辑模式(另一个视图控制器)并使用数据填充UITextFields。目前,当我按下表格中的单元格时,应用程序崩溃,抛出此异常:

[UINavigationController setDevice:]: unrecognized selector sent to instance 0xc548f20
2014-07-07 20:23:37.157 MyApp[20241:1250380] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setDevice:]: unrecognized selector sent to instance 0xc548f20'

以下是准备传输数据的segue的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"Update"]) {
        NSManagedObject *selectedDevice = [self.devices objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
        SecondViewController *destViewController = segue.destinationViewController;
        NSLog(@"1");
        destViewController.device = selectedDevice;
        NSLog(@"2");

    }
}

我认为问题是因为我有一个导航控制器作为segue的目的地,当它应该是连接到导航控制器的视图控制器时。我该如何解决这个问题?

ADDED

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"Update"]) {
        NSManagedObject *selectedDevice = [self.devices objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
        SecondViewController *destViewController = segue.destinationViewController;
        NSLog(@"1");

        UINavigationController * nvc = segue.destinationViewController;
        SecondViewController * vc = nvc.viewControllers[0];

        destViewController.device = selectedDevice;

        NSLog(@"2");

    }
}

1 个答案:

答案 0 :(得分:1)

试试这个:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([[segue identifier] isEqualToString:@"Update"])
        {
            NSManagedObject *selectedDevice = [self.devices objectAtIndex:[[self.tableView indexPathForSelectedRow] row]];
            UINavigationController * nvc = segue.destinationViewController;
            SecondViewController * vc = nvc.viewControllers[0];
            vc.device = selectedDevice;
        }
    }