自定义uitableviewcell内的按钮不起作用 [英] Button inside a custom uitableviewcell not working
本文介绍了自定义uitableviewcell内的按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义TableCell,并且通过IB将UiButton与之关联.但是按钮操作方法始终将按钮索引返回为零
I have a custom TableCell and a UiButton is associated with this via IB. But the button action method always return the button index as zero
下面是我的代码
//Inside CellForRow
[cell.M_CtrlBtnChat addTarget: self
action: @selector(buttonPressed:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
- (void) buttonPressed: (id) sender withEvent: (UIEvent *) event
{
UITouch * touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: location];
NSLog(@"%d", indexPath.row);
}
此处索引路径始终返回零. 任何的想法 .请帮助我
Here index path always return zero. Any idea . Please help me
推荐答案
[cell.M_CtrlBtnChat addTarget: self
action: @selector(buttonPressed:withEvent:)
forControlEvents: UIControlEventTouchUpInside];
cell.M_CtrlBtnChat.tag = indexPath.row;
- (void) buttonPressed: (id) sender withEvent: (UIEvent *) event
{
UIButton *btn = (UIButton *)sender;
NSLog(@"btn.tag %d",btn.tag);
UITouch * touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView: self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint: location];
NSLog(@"%d", indexPath.row);
}
尝试此操作可能会对您有所帮助.
try this it may help you.
这篇关于自定义uitableviewcell内的按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文