因此,我将 didSelectRowAtIndexPath 方法放入了 UITableViewController 中。

TableView转到由 NavigationController 控制的 UIViewController

我想将indexPath.row 发送到NavigationController调用的类,有什么方法可以将参数发送到另一个类吗?

我的应用方案是:

TabBarController ---> NavigationController ---> TableViewController ---> UIViewController

最佳答案

如果您使用情节提要:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UITableViewCell *cell = sender;
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
    {
        // Get reference to the destination view controller
        YourViewController *vc = [segue destinationViewController];
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];

        // Pass any objects to the view controller here, like...
        [vc setIndexPath:indexPath];
    }
}

其他
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        YourViewController *vc = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
        [vc setIndexPath:indexPath];
    }

}

10-08 13:10