0
我正在使用Coredata和NSFetchedResultsController存储和检索值并在表格视图中显示它们。我在cellForRowAtIndexPath
中创建自定义标签并显示属性'lastname'的值。但我收到错误的价值。UILabel在UITableView中显示错误的值
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *label = nil;
if(cell == nil){
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
label = [[[UILabel alloc]initWithFrame:CGRectMake(160,10,120,21)]autorelease];
label.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:label];
//Configure the cell
List *list = [self.fetchedResultsController objectAtIndexPath:indexPath];
label.text = list.lastname;
}
[self configureCell:cell atIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
的奇怪的是,它是工作正常,如果我除去UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
线和如果条件。
仍然没有工作 – 2013-04-29 14:26:29
编辑我的答案。这应该现在工作 – gasparuff 2013-04-29 14:27:05
把它放在你的'[self configureCell:cell atIndexPath:indexPath];' – gasparuff 2013-04-29 14:27:40