当 UITableView 行被选择时,prepareForSegue 没有被调用?

发布于 2025-01-08 02:55:52 字数 1100 浏览 1 评论 0原文

我已经使用 NSFetchedResultsController 设置了一个 UITableView,它显示了许多原型 UITableViewCell。我已经连接了从 UITableViewCell 到 DetailViewController 的推送 Segue。

在我的 TableViewController 中,我已经实现了两者:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

当我运行应用程序并单击 tableView 中的一行时,我的应用程序仅调用:

[TableViewController tableView:didSelectRowAtIndexPath:]
[TableViewController tableView:didSelectRowAtIndexPath:]
[TableViewController tableView:didSelectRowAtIndexPath:]

如果我删除 segue 并将其从 UIBarButtonItem 重新连接到 DetailViewController,则可以正确调用 segue,任何人都可以认为我缺少什么?

编辑:

添加:

- (IBAction)tester:(id)sender {
    [self performSegueWithIdentifier:@"SEGTEST" sender:nil];
}

并将其连接到名为“tester”的 UIButtonBarItem 并且它可以工作,当我从 UITableViewCell 链接到控制器时,我只是无法让它继续触发。

I have setup a UITableView using a NSFetchedResultsController that displays a number of prototype UITableViewCells. I have hooked up a push segue from my UITableViewCell to my DetailViewController.

In my TableViewController I have implemented both:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%s", __PRETTY_FUNCTION__);
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

When I run the application and click on a row in the tableView my application only calls:

[TableViewController tableView:didSelectRowAtIndexPath:]
[TableViewController tableView:didSelectRowAtIndexPath:]
[TableViewController tableView:didSelectRowAtIndexPath:]

If I delete the segue and rewire it form a UIBarButtonItem to the DetailViewController then the segue is called correctly, can anyone think what I am missing?

EDIT:

Added:

- (IBAction)tester:(id)sender {
    [self performSegueWithIdentifier:@"SEGTEST" sender:nil];
}

and connected it unto a UIButtonBarItem that called "tester" and it works, I just can't get it to fire still when I link from the UITableViewCell to the controller.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女皇必胜 2025-01-15 02:55:52

经过一番挖掘,我最终发现 UITableViewCell 标识符被错误地设置为“CELL_ID”,而它应该是“PLANTCELL_ID”。

如果其他人发现在 UITableView 中选择 UITableViewCell 不会调用关联的 segue,请检查您的单元格标识符在故事板和tableView:cellForRowAtIndexPath:

After a bit of digging I eventually found that the UITableViewCell identifier was set incorrectly to "CELL_ID" when it should have been "PLANTCELL_ID".

Som for anyone else who finds that selecting a UITableViewCell in a UITableView does not call the associated segue, check if your cell identifier is set correctly in both the storyboard and tableView:cellForRowAtIndexPath:.

毅然前行 2025-01-15 02:55:52

从 ViewController 本身重新连接 Segue 并为其命名。
然后在 didSelectRow 方法中调用

[self performSegueWithIdentifier:@"yourSegueName"];    

并查看它是否触发。

Rewire your segue from the ViewController itself and give it a name.
Then in the didSelectRow method call

[self performSegueWithIdentifier:@"yourSegueName"];    

and see if it fires.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文