I have a custom UITableViewCell, called EventCell
.
EventCell.h
#import
@interface EventCell : UITabl
You need to implement
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:nil];
}
You shouldn't have to implement didSelectRow
for this to work - control-dragging from a cell to another view controller should create a segue that works when tapping the cell.
In my case, the problem was that the storyboard editor was creating the segue incorrectly. I had two very similar storyboards, one worked and the other didn't, and looking at the source code (right click on the storyboard file and choose Open As -> Source Code), I saw this:
<segue destination="UWX-rF-KOc" kind="replace" identifier="showStory" trigger="accessoryAction" splitViewControllerTargetIndex="1" id="Gly-La-KIe"/>
Note the trigger
attribute. This suggests to me that the segue will be fired from the accessory action of the cell. You can even see this from the connections inspector of the cell:
Removing this and replacing the segue by dragging from the "selection" handle above instead of control-dragging from the cell gave me the correct segue.
I'm not sure what it is about this particular cell that makes control-dragging connect to the accessory action instead of the selection action, but there you go.
As stated above, you need to use didSelectRowAtIndexPath
unless you configure a segue in your storyboard to a new UIViewController
. This allows you to use the prepareForSegue
function instead of the programmatic call of performSegueWithIdentifier
.
Hope that helps clear it up!
My problem was the cell identifier.
So, in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
I declared static NSString *cellIdentifier = @"cell";
and then in storyBoard I added this identifier in here:
And here you go!