How to add multiple buttons to an additional view of a UITableView?

I want to add two adjacent custom buttons to a UITableView accessory.

I tried doing cell.accessoryView = customButton;and then cell.accessoryView = customButton2. Obviously, this replaces the previous button.

Thanks for any help!

+4
source share
2 answers

You can add a UIView containing two buttons as a custom accessory.

UIView *buttonsView = [...];
// add buttons to buttonsView
cell.accessoryView = buttonsView;

Or you can subclass UITableViewCell and add two buttons there.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {
        UIButton *buttonA = ....
        UIButton *buttonB = ....
        [self.contentView addSubview:buttonA];
        [self.contentView addSubview:buttonB];
    }

    return self;
}

If you have not created a custom UITableViewCell before this article can help.

http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells--mobile-15702

+3
source

UIView , ( subviews: [self addSubview:button]). UIView .

cell.accessoryView = yourCustomView;

+1

Source: https://habr.com/ru/post/1529187/


All Articles