iOS indexPath 为零(自定义附件图像)
我使用了 Apple 的“配件”示例代码,在我的表格中添加了自定义配件图像。该表正确地渲染了图像和所有内容,但是当我单击应该带我进入 accessoryButtonTappedForRowWithIndexPath 方法的图像时,没有任何反应,因为由于某种原因 indexPath 为零。请参阅此方法来检查indexPath:
- (void)accessoryButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
I've used the sample code from Apple for "Accessory" to have a custom accessory image in my table. The table renders the image properly and everything but when I click on the image that is supposed to take me to the accessoryButtonTappedForRowWithIndexPath method nothing happens because indexPath is nil for some reason. See this method which checks the indexPath:
- (void)accessoryButtonTapped:(id)sender event:(id)event
{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不能在
UITableViewDelegate
中使用tableView:accessoryButtonTappedForRowWithIndexPath:
?Why can't you just use
tableView:accessoryButtonTappedForRowWithIndexPath:
in yourUITableViewDelegate
?