2012-08-09 47 views
0

我目前正在學習目標c,並且正在嘗試從表視圖創建一個segue到另一個視圖。並且代碼在prepareForSegue函數中崩潰。從TableView的segue

繼承人的代碼

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
if([segue.identifier isEqualToString:@"rowSelected"]){ 
    UIViewController *nextViewController = segue.destinationViewController; 
    nextViewController.title = @"newView"; 
    } 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
[self performSegueWithIdentifier:@"rowSelected" sender:self]; 
} 

我的理解爲賽格瑞準備的是,我沒有初始化的下一個視圖(?)。但是我看過的大多數教程僅在prepareForSegue中設置了一些配置。

有沒有什麼明顯的即時通訊做錯了?或者也許有人可以鏈接一個tableview + segue指南,所以我可以通過並發現我自己做錯了什麼。

繼承人的錯誤消息,至少,我發現實際包含的信息

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[notesViewController length]: unrecognized selector sent to class 0x469c' 
+0

這個錯誤意味着你要求一個樂ngth屬性來自沒有對象的對象。我沒有看到你的代碼有什麼問題。 – Dustin 2012-08-09 13:45:15

+0

這就是你在prepareForSegue中所擁有的一切嗎? – Moxy 2012-08-10 01:58:36

回答

0

你好皮塔試試這個代碼

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
if([segue.identifier isEqualToString:@"rowSelected"]){ 
    UIViewController *nextViewController = segue.destinationViewController; 
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
nextViewController.title = [YourSomethingArray objectAtIndex: indexPath.row]; 
    } 

yourSomethingArray從您的代碼中找到以上部分

cell.textLabel.text = yourSomethingArray[indexPath.row];