【问题标题】:iOS indexPath is nil (custom accessory image)iOS indexPath 为 nil(自定义附件图片)
【发布时间】:2011-05-13 21:26:45
【问题描述】:

我已使用 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];
    }
}

【问题讨论】:

    标签: cocoa-touch ios nsindexpath accessoryview


    【解决方案1】:

    为什么不能在UITableViewDelegate 中使用tableView:accessoryButtonTappedForRowWithIndexPath:

    【讨论】:

    • 我需要使用此方法,以便可以使用自定义附件图像(如 Apple 的“附件”示例代码中所示)。尽管在该示例代码中,Apple 使用 UITableViewController 作为具有 tableView ivar 的父类。我正在使用没有 tableView ivar 的 UIViewController 类。那么我可以为我的 UIViewController 类创建 tableView ivar 吗?
    • 是的,如果您在 Interface Builder 中创建表,请创建一个 IBOutlet。如果您在代码中创建它,只需在头文件中声明 ivar。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多