gpt4 book ai didi

ios - 无法从 uitablecell 打开 View Controller

转载 作者:行者123 更新时间:2023-11-29 04:13:07 25 4
gpt4 key购买 nike

我有一个 uitableview,我想按下它时打开一个新的 viewController。

我使用的这段代码可以在其他类中使用,但在这个类中则不行。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"Row selected:%d",indexPath.row);
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:@"SingleCamera"] animated:YES];

}

我不知道为什么,因为这是我迄今为止使用的代码。它不会播放我输入的任何标识符,它只是不会去任何地方。

我也试过这个:

[self performSegueWithIdentifier:@"SingleCamera" sender:tableView];

但我收到 NSInvalidargument 错误

编辑:我的项目的结构是这样的:我有一个导航 Controller 和一个初始 View A。从 View A,我将使用完全相同的代码查看 B。从 View B 我要查看 C,在 Storyboad 内部使用 Segue 模式模态,在 View C 中是使用上述代码的 tableviewcontroller。

最佳答案

改为这样写:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Row selected:%d",indexPath.row);
UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SingleCamera"];
[[self navigationController] pushViewController:viewController animated:YES];
}

并在带有 pushView... 的行设置一个断点,以查看 viewController 是否已实例化。

编辑:

关于performSegue...,让您在 Storyboard中拥有该segue。

关于ios - 无法从 uitablecell 打开 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14090680/

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