所以我将 didSelectRowAtIndexPath 方法放入 UITableViewController 。
TableView转到 UIViewController ,由 NavigationController 控制。
我想将indexPath.row 发送到NavigationController调用的类,有没有办法将参数发送到另一个类?
我的应用方案是:
TabBarController ---> NavigationController ---> TableViewController --->的UIViewController
答案 0 :(得分:0)
如果您使用的是故事板:
- (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];
}
}