更改为UITableViewController后,indexPath为nil

时间:2013-12-17 17:29:47

标签: objective-c uitableview uistoryboard

由于我将视图更改为Storyboard中的UITableViewController,因此我的indexPath为nil。有人可以发现错误吗?我用segues。我已经将TableViewController中的虚拟单元连接到新的TableViewController。两者都在UINavigationController中推送

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

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Assume self.view is the table view
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    Country *country = (Country *)[fetchedResultsController objectAtIndexPath:path];

    if ([segue.identifier isEqualToString:@"selectCountry"])
    {
        CaveTableViewController *ctvc = [segue destinationViewController];
        ctvc.country = country;
        ctvc.navigationItem.title = country.country;
    }

    [self.tableView deselectRowAtIndexPath:path animated:YES];
}

1 个答案:

答案 0 :(得分:1)

尝试更改:

NSIndexPath *path = [self.tableView indexPathForSelectedRow];

致:

NSIndexPath *path = [self.tableView indexPathForCell:sender];