segue from TableView



我目前正在学习目标c,我正在尝试创建一个从表视图到另一个视图的segue。 并且代码在 prepareForSegue 函数处崩溃。

这是代码

- (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];
}

我对 segue 准备的理解是我在那里初始化下一个视图(? 但是我看过的大多数教程只在 prepareForSegue 中设置了一些配置。

有什么明显的我做错了吗? 或者也许有人可以链接 tableview + segue 指南,这样我就可以跟进并找到我自己做错了什么。

这是错误消息,至少是我发现实际包含信息的部分

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

你好皮塔试试这个代码

- (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];
    }
你的

代码在上面找到你的东西数组

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

最新更新