当 UITableView 行被选择时,prepareForSegue 没有被调用?
我已经使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一番挖掘,我最终发现
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 aUITableView
does not call the associated segue, check if your cell identifier is set correctly in both the storyboard andtableView:cellForRowAtIndexPath:
.从 ViewController 本身重新连接 Segue 并为其命名。
然后在
didSelectRow
方法中调用并查看它是否触发。
Rewire your segue from the
ViewController
itself and give it a name.Then in the
didSelectRow
method calland see if it fires.