我有以下代码来填充uitableview单元格上的数据。出于某种原因,我在桌面视图中看到每个项目正好两个。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"takeStockCell";
UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
RackStockTakeStatus *rackStockTakeStatus = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = rackStockTakeStatus.locName;
if ([[rackStockTakeStatus.status lowercaseString] isEqualToString:@"inprogress"])
{
cell.detailTextLabel.textColor = [UIColor blueColor];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ [%@]",rackStockTakeStatus.status,rackStockTakeStatus.stockTakeByUser];
} else if ([[rackStockTakeStatus.status lowercaseString] isEqualToString:@"completed"])
{
cell.detailTextLabel.textColor = [UIColor colorWithRed:(0/255.0) green:(102/255.0) blue:(0/255.0) alpha:1];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ [%@]",rackStockTakeStatus.status,rackStockTakeStatus.stockTakeByUser];
} else if ([[rackStockTakeStatus.status lowercaseString] isEqualToString:@"verified"])
{
cell.detailTextLabel.textColor = [UIColor colorWithRed:(0/255.0) green:(102/255.0) blue:(0/255.0) alpha:1];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ [%@]",rackStockTakeStatus.status,rackStockTakeStatus.stockTakeByUser];
}
}
答案 0 :(得分:-1)
我不确定你的方法是如何配置单元格的。您是否尝试将其直接配置到方法cellForRowAtIndexPath中?不要将单元格作为参数。
或者只是在方法configure
中返回单元格cell = [self configureCell...