我有一個php文件,它返回帶有id /值對的XML。 當我解析XML時,我創建了一個對象數組,每個對象都有一個id和一個值。 我現在所做的是將XML中的值添加到單元格文本中。也想存儲相應的ID,所以我可以在didSelectRowAtIndexPath方法中使用它。 我很新的iPhone,所以這可能是顯而易見的,不好意思:)iphone - 在tableview中存儲id /值對
目前我的cellForRowAtIndexPath方法是這樣的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
int categoryIndex = [indexPath indexAtPosition: [indexPath length] -1];
cell.textLabel.text = [[categories objectAtIndex: categoryIndex] objectForKey: @"CategoryName"];
cell.accessoryType = UITableViewCellSelectionStyleBlue;
return cell;
}
類別對象的定義,像這樣:
category = [[NSMutableDictionary alloc] init];
[category setObject:currentID forKey:@"CategoryId"];
[category setObject:currentName forKey:@"CategoryName"];
謝謝!我實際上會選擇繼承。 – 2011-06-16 23:51:08