I would probably subclass UIButton to have an instance of NSIndexPath. That way, each individual UIButton in a UITableViewCell can "know" where it is in the table view, so when you press the button, you can call some method that takes an NSIndexPath and pushes a new view, similar to what you do in -didSelectRowAtIndexPath:
but with your other view instead (maybe give it a descriptive method name like -didPressButtonAtIndexPath:
).
Instead of using the Interface Builder to do this, you should add a method to the UIButton subclass itself that in turn calls a method on your view controller. Then, for each UIButton, you can use the UIControl method -addTarget:action:forControlEvents:
. Have the UIButton call its own method, which calls the controller's method. Your solution might look something like:
// MyButton.h
@interface MyButton : UIButton {
NSIndexPath *myIndexPath;
MyViewController *viewController;
}
- (void)didPressButton;
@end
// MyViewController.h
@interface MyViewController { }
- (void)didPressButtonAtIndexPath:(NSIndexPath *)indexPath;
@end
Then, when you build your cells, for each button you add call:
[button addTarget:button
action:@selector(didPressButton)
forControlEvents:UIControlEventTouchDown];
And finally, implement -didPressButton
to look like:
- (void)didPressButton {
[controller didPressButtonAtIndexPath:myIndexPath];
}