为AccessoryType TableView添加"加号"按钮

teo*_*teo 7 iphone uitableview accessorytype

我正在尝试实现一个TableView,其中每个单元格都有一个' +'按钮,就像在播放列表中添加歌曲时的iPod应用程序一样.

cell.accesoryType只有四个值

UITableViewCellAccessoryCheckmark

UITableViewCellAccessoryDetailDisclosureButton
Run Code Online (Sandbox Code Playgroud)

UITableViewCellAccessoryDisclosureIndicator

None
Run Code Online (Sandbox Code Playgroud)

如何才能做到这一点?我是否需要创建自定义按钮并设置cell.accessoryView或是否有其他方法来执行此操作?

Jos*_*phH 13

Teo的解决方案效果很好,但它没有作为答案发布,所以我重新发布它:

UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button addTarget:self action:@selector(addbuttonTapped) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
Run Code Online (Sandbox Code Playgroud)


小智 0

如果您要创建一个,则在其右上角custom cell放置一个,就像出现的地方一样,并将其指定为按钮的“+”图像,这样您也可以“看到图像”并获得“按钮操作事件”。buttonaccessory type

有关自定义 uitableviewcells,请参阅教程。

  • 找到解决方案 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [按钮 addTarget:self 操作:@selector(buttonTapped:event:) forControlEvents:UIControlEventTouchUpInside]; cell.accessoryView = 按钮;并创建了事件处理过程 - (void)buttonTapped:(id)sender event:(id)event { } (5认同)