我正在从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");
}
}
答案 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;
}
}