【问题标题】:How to assign a custom extra parameter beside 'NSIndexPath' when select a UITableViewCell?选择 UITableViewCell 时如何在“NSIndexPath”旁边分配自定义额外参数?
【发布时间】:2012-01-15 13:40:51
【问题描述】:

我用 sqlite db 表记录制作了一个 UITableView 填充单元格数据。每个 UITableViewCell 是一个与表记录相关的记录。

现在我想使用 - (void) tableView : (UITableView *) tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法转到记录详细信息视图,我想从包含记录的表中选择ID。但是这个 didSelectRow 方法有 indexPath 参数,我可以写

- (id) initWithIndexPath:(NSIndexPath *)indexPath {
    if (self = [super init ]) {
        index = indexPath;
    }
    return self;
}

但现在我想纠正一个方法 initWithCityId 方法

- (id) initWithCityId: (NSString * )_cityId {

}

如何将此额外参数(记录ID属性)分配给详细信息查看控制器时选择了UITableViewCell?

【问题讨论】:

    标签: iphone ios xcode uitableview


    【解决方案1】:

    假设城市 ID 是您的表视图数据源的一部分,请在 didSelectRow... 方法中获取它,就像在 cellForRowAtIndexPath... 中一样,然后您可以将其传递给(大概)您的详细视图控制器。

    【讨论】:

    • 如何假设单元格的城市 ID?
    • 我不明白。您希望使用的 cityID 是什么?数据从何而来?
    【解决方案2】:

    据我所知,您可以使用这些属性来解决您的问题,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-08
      • 2010-11-19
      相关资源
      最近更新 更多