【发布时间】:2013-07-22 10:59:39
【问题描述】:
我有一个自定义的 TableCell 和一个 UiButton 通过 IB 与它相关联。但是按钮操作方法总是将按钮索引返回为零
下面是我的代码
//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);
}
这里的索引路径总是返回零。 任何的想法 。请帮帮我
【问题讨论】:
-
什么是
self?你的表格视图单元格?它有tableView属性吗?当你NSLog(@"%@", self.tableView)时会发生什么? -
请记住,您可以使用关联对象将 indexPath 直接关联到表格视图单元格。
-
@Vishnu 你试过我的答案了吗?
-
@Vishnu,你的代码是正确的。你能发布你的'cellForIndexPath'方法
标签: iphone ios objective-c ipad uitableview