prepareForSegue not called when UITableView row selected?

こ雲淡風輕ζ 提交于 2019-12-12 07:25:33

问题


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.


回答1:


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:.




回答2:


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.



来源:https://stackoverflow.com/questions/9400429/prepareforsegue-not-called-when-uitableview-row-selected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!