如何在UITableView的辅助视图中添加多个button?
我想在UITableView的附件视图中添加两个相邻的自定义button。
我试过做cell.accessoryView = customButton;
然后cell.accessoryView = customButton2
很明显,这取代了以前的button。
谢谢你的帮助!
你可以添加一个包含两个button的UIView作为一个自定义的accessoryView。
UIView *buttonsView = [...]; // add buttons to buttonsView cell.accessoryView = buttonsView;
或者你可以inheritanceUITableViewCell并在其中添加两个button。
- (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; }
如果您在本文可能有所帮助之前还没有做过自定义的UITableViewCell。
http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells–mobile-15702
您可以使用放置在其中的button来创build自定义的UIView类(作为子视图: [self addSubview:button]
)。 然后,您可以将您的自定义UIView对象指定为cellView的accessoryView。
cell.accessoryView = yourCustomView;