2014-07-08 70 views
1

我正在將內容從Core Data模型加載到UITableView控制器中,並且希望能夠按下數據點並使其打開編輯模式(另一個視圖控制器)並填充帶有數據的UITextFields。目前,當我按上表中的單元格,拋出該異常的應用程序崩潰:由於核心數據Segue轉移而崩潰的應用程序

[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"); 

    } 
} 

我相信這個問題是因爲我有一個導航控制器作爲我的目的地,當它真的應該是連接到導航控制器的視圖控制器。我該如何解決?

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

試試這個:

- (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; 
     } 
    } 
+0

我的應用仍然與添加的代碼崩潰。我編輯了這個問題來展示我的新嘗試。 –

+0

我編輯了我的答案。您應該將selectedDevice分配給vc而不是destViewController,因爲vc是SecondViewController,而destViewController是UINavigationViewController @ C-O-D-E – ukim

+0

好的答案!謝謝! –