View custom accessories on the UITableView Prototype Cell Not Firing

I have a custom accessory view (UIButton) in my prototype cell in the storyboard. When I click on this button, the delegate method for the Accessory button is not called. If I use the standard disclosure button, it’s called just fine. I assume that I am missing a connection somewhere. Does anyone know where?

+5
source share
3 answers

I ended up working on this using the protocol for user table cells.

CustomAccessoryTableCellDelegate.h

@protocol CustomAccessoryTableCellDelegate <NSObject>

     @required
     - (void) accessoryButtonTappedForCell: (UITableViewCell *) cell;

@end

CustomAccessoryViewTableCell.h

 @interface CustomAccessoryViewTableCell : UITableViewCell

      /** The custom accessory delegate. */
      @property (nonatomic, weak) id<CustomAccessoryTableCellDelegate> delegate;

 @end

CustomAccessoryViewTableCell.m

- (IBAction) buttonAction:(id)sender{

    if ([self.delegate respondsToSelector:@selector(accessoryButtonTappedForCell:)]) {
        [self.delegate accessoryButtonTappedForCell:self];
    }

}

Internal table view controller

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    CustomAccessoryViewTableCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:@"MyCustomCell"];

    cell.label.text = @"Some Name";
    cell.delegate = self;

    return cell;
 }

#pragma mark - Custom Accessory View Delegate

- (void) accessoryButtonTappedForCell:(UITableViewCell *)cell{
    [self tableView:self.writerTable 
        accessoryButtonTappedForRowWithIndexPath: [self.writerTable
                                                      indexPathForCell:cell]];
}
+1
source

1: " ", UIButton, , . , .

2: , "", UIButton, , . UIView.

, .

+2

apple docs

( ), , . , indexPath .

therefore, it is not intended for custom types of accessories. this is standard behavior.

+2
source

All Articles