I have a tableview and I have plugged in a segue in its cell. i want given a condition, to either enable or disable the cell.
This is my code inside the didSelectRowAtIndexpath
if (condition) {
NSLog(@"Nothing);
} else {
[self performSegueWithIdentifier:@"segueName" sender:tableView];
}
But segue gets called every time, even if I do see the NSLog printed.
Some answers here said that I should place the segue in the view controller but in the storyboard I cannot do it, I can only place it into the cell.
What have I missed?
Do you also have the segue going from the cell to the next scene in Interface Builder? If so, that will be called, regardless of what
didSelectRowAtIndexPathdoes.Two approaches are possible:
If iOS 6-only, you can eliminate
didSelectRowAtIndexPathaltogether, put the segue between the cell and the next scene, and then implementshouldPerformSegueWithIdentifierand put your conditional logic there, e.g.If you need compatibility with iOS 5, you should remove the segue between the cell and the next scene, but have it go between the view controllers (i.e. you control-drag from the first view controller’s icon in the bar at the bottom of the scene to the next scene). That way, the segue is defined, but not hooked up to the cell. And your
didSelectRowAtIndexPathcan use the conditional logic you suggest in your question: