我正在尝试实现一个TableView,其中每个单元格都有一个'+
‘按钮,就像向播放列表添加歌曲时的iPod应用程序一样。
cell.accesoryType
只有四个值
UITableViewCellAccessoryCheckmark
UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryDisclosureIndicator
和
None
如何做到这一点?我是否需要创建一个自定义按钮并设置cell.accessoryView
,或者是否有其他方法可以做到这一点?
发布于 2012-10-01 03:01:04
Teo的解决方案工作得很好,但它并没有作为答案发布,所以我重新发布了它:
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button addTarget:self action:@selector(addbuttonTapped) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
发布于 2014-04-02 17:57:14
JosephH的一个简单变体,用于内存。
如果您只是想要一个装饰性的"+“按钮并继续使用原始的didSelectRowAtIndexPath触发器,请使用:
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button setUserInteractionEnabled:NO];
cell.accessoryView = button;
通过禁用按钮上的用户交互,它将在底层视图:单元格上传播压力事件。
发布于 2011-06-11 16:40:10
如果你正在创建一个按钮,那么在它的右上角放置一个button
,就像accessory type
出现的地方,并将你的'+‘图像分配给按钮,这样你也可以“看到图像”并获得“custom cell
action event”。
有关自定义uitableviewcell的信息,请参阅this教程。
https://stackoverflow.com/questions/6314958
复制相似问题