gpt4 book ai didi

ios - 将 indexPath.row 发送到另一个 UIViewController

转载 作者:行者123 更新时间:2023-12-01 16:55:24 25 4
gpt4 key购买 nike

所以我有 didSelectRowAtIndexPath 方法转换为 UITableViewController .

TableView 转到 UIViewController 控制导航 Controller .

我要发送 indexPath.row 到 NavigationController 调用的类,有没有办法 将参数发送到另一个类 ?

我的应用方案是:

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

最佳答案

如果您使用 Storyboard :

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

}

关于ios - 将 indexPath.row 发送到另一个 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12230402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com