A UITableViewCell subclass, intended to be subclassed, to forward action messages from cell subviews to a controller.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This class is a superclass for UITableViewCells that have UIControl instances as subviews.  Typically, you want the target of these UIControls to be the controller responsible for the table view that the cell belongs to. You also want to know from which index path the control was tapped. Tagging a cell with a number is insufficient and clumsy, so BNRXIBCell takes another approach. BNRXIBCell also hides the registration process. I've only barely just tested it, but it works for now. I may also add model object binding if I feel like it makes configuring a cell easier.


1. Create a subclass of BNRXIBCell. 

2. Create a XIB file where the first top-level object is an instance of your BNRXIBCell subclass by dragging a UITableViewCell onto the canvas and changing its identity.

3. For all UIControl action messages, declare them in the BNRXIBCell subclass. 

@interface MyCell : BNRXIBCell
- (IBAction)action:(id)sender;

4. Connect UIControl instances in XIB file to the cell subclass in the outline view (not the file's owner).

5. Implement the action as follows:

- (IBAction)action:(id)sender

6. In your controller, use the cells like so:

- (UITableViewCell *)tableView:(UITableView *)tv
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
    // This takes care of registering the NIB or class.
    MyCell *cell = [MyCell cellForTableView:tv target:self];
    // configure cell
    return cell;

7. Then, implement the action method in your controller. The first label of the selector must always be the same as the IBAction and the second label must always be atIndexPath:

- (void)action:(id)sender atIndexPath:(NSIndexPath *)ip
    NSLog(@"Control event from %@ at %@", sender, ip);