要使用accessoryView - 您需要将单元格的accessoryType设置为UITableViewCellAccessoryNone将UIButton(与关联图像)存入单元格,然后将其连线以接收用户触摸。你可以使用类似下面的代码为IBAction为响应细胞的UIButton的被感动:
- (IBAction) accessoryButtonPressed:(id) sender
{
NSUInteger pathInts[] = { 0,0 };
pathInts[1] = self.currentselectedrow; // ivar set when tableview row last selected
NSIndexPath* indexPath = [NSIndexPath indexPathWithIndexes:pathInts length:2];
[self tableView:mytableview accessoryButtonTappedForRowWithIndexPath:indexPath];
}
的UIButton的将有线你的tableview的“的cellForRowAtIndexPath:”里面的线路的方式来执行这种胶码功能
[thecell setButtonTarget:self action:@selector(accessoryButtonPressed:)];
我注意到的一件事是,UIButton似乎想要一个'向右滑动'而不是简单的'点击'触摸来触发事件 - 但它可能是我的iOS iOS版本的问题。请注意,我已将一个名为'cell_accessoryButton'的UIButton *对象添加到Custom Cell源。
在细胞的来源,你会支持的代码像这样“setButtonTarget”呼叫:
- (void) setButtonTarget:(MyViewController*)inTarget action:(SEL) inAction
{
[self.cell_accessoryButton addTarget: inTarget
action: (SEL) inAction
forControlEvents: UIControlEventTouchUpInside];
}
它是如此容易得多只使用accessoryType参考,并让iOS的做繁重的 - 但是,如果你想要一个自定义的图形等 - 这是另一条有效的路径。
这篇文章的任何链接? :) – Hulvej
PFB链接..http://www.edumobile.org/iphone/iphone-programming-tutorials/impliment-a-custom-accessory-view-for-your-uitableview-in-iphone/ – Jhaliya