【发布时间】:2011-11-27 17:15:45
【问题描述】:
如何引用在 didSelectRowAtIndexPath:(NSIndexPath *)indexPath 方法中单击的单元格对象?
我有一个 UISplitViewController,在 MasterView 中我有一个表格,其中 cell.tag = sqlite 数据库中的主键的单元格(即表格是从 db 填充的)。我能够在上述方法中捕获点击事件,但是我看不到如何将单元格对象传入,或者我如何引用它以获取 cell.tag。最终,目标是通过 Master/Detail 委托将该 id 传递给详细视图,然后根据来自 Master 的 id 将数据加载到 DetailView。
感谢任何提示!
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text = NSLocalizedString(@"Detail", @"Detail");
Entry *entry = [self.entries objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[NSString stringWithFormat:@"%@",entry.title]];
cell.tag = entry.entryID;
return cell;
}
【问题讨论】:
标签: iphone ios cocoa-touch ipad