Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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 <code>-didSelectRowAtIndexPath:</code> but with your other view instead (maybe give it a descriptive method name like <code>-didPressButtonAtIndexPath:</code>).</p> <p>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 <code>-addTarget:action:forControlEvents:</code>. Have the UIButton call its own method, which calls the controller's method. Your solution might look something like:</p> <pre><code>// MyButton.h @interface MyButton : UIButton { NSIndexPath *myIndexPath; MyViewController *viewController; } - (void)didPressButton; @end // MyViewController.h @interface MyViewController { } - (void)didPressButtonAtIndexPath:(NSIndexPath *)indexPath; @end</code></pre> <p>Then, when you build your cells, for each button you add call:</p> <pre><code>[button addTarget:button action:@selector(didPressButton) forControlEvents:UIControlEventTouchDown];</code></pre> <p>And finally, implement <code>-didPressButton</code> to look like:</p> <pre><code>- (void)didPressButton { [controller didPressButtonAtIndexPath:myIndexPath]; }</code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload