The general idea is that you cell should tell your view controller that something happened and than is the View Controller that will decided to push the other View Controller.
You can do that with the delegate design pattern:
ItemCell
has a delegate
property that conform to a protocol. For example
@class ItemCell
@protocol ItemCellDelegate
- (void)itemCellDidClickSubmitButton:(ItemCell *)cell;
@end
@interface ItemCell
@property (nonatomic, weak) id<ItemCellDelegate> delegate
...
@end
In tableView:cellForRowAtIndexPath:
you will set the controller as the cell delegate (obviously the view controller should conform to the ItemCellDelegate
):
cell.delegate = self
The button on your cell will trigger an IBAction on the cell itself that in turn will call the delegate method
- (IBAction)submitButtonTapped:(id)sender
{
id <ItemCellDelegate> delegate = self.delegate;
if ([delegate respondToSelector:@selector(itemCellDidClickSubmitButton:)]) {
[delegate itemCellDidClickSubmitButton:self];
}
}
And obviously in your View Controller you should do something like:
#pragma mark - ItemCellDelegate
- (void)itemCellDidClickSubmitButton:(ItemCell)cell
{
UIViewController *controller = // Create the view controller to push
[self.navigationController pushViewController:controller];
}