如何在 UITableView 的附件视图中添加多个按钮? [英] How to add multiple buttons in accessory view of UITableView?

查看:29
本文介绍了如何在 UITableView 的附件视图中添加多个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UITableView 的附件视图中添加两个相邻的自定义按钮.

I want to add two adjacent custom buttons in the UITableView's accessory view.

我试着做 cell.accessoryView = customButton; 然后cell.accessoryView = customButton2 .很明显,这取代了之前的按钮.

I tried doing cell.accessoryView = customButton; and then cell.accessoryView = customButton2 .It is obvious that this replaces the previous button.

感谢您的帮助!

推荐答案

您可以添加一个包含两个按钮的 UIView 作为自定义的附件视图.

You can add a UIView containing the two buttons as a custom accessoryView.

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

或者你可以继承 UITableViewCell 并在那里添加两个按钮.

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;
}

如果你在这篇文章之前没有做过自定义 UITableViewCell 可能会有所帮助.

If you haven't done a custom UITableViewCell before this article might help.

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

这篇关于如何在 UITableView 的附件视图中添加多个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆