我需要使用什么方法来确保没有空单元格被绘制到视图当前其绘制空单元格,所以我尝试放置以下代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier2 = @"Cell2";
UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
if (cell2 == nil ||[cell2.textLabel.text isEqualToString:@"(null)"]) {
NSLog(@"Came inside cell2 == nil");
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2];
}
else {
NSLog(@"inside else statement");
[self configureCell:cell2 atIndexPath:indexPath];
}
NSString *text = cell2.textLabel.text;
NSLog(@"OUtput - item 1 - Cell2:: %@",text);
return cell2;
}
上面的代码似乎没有做任何事情,仍然绘制没有内容的空单元格。如何阻止它?
configureCell的代码
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [[object valueForKey:@"dbTextField"] description];
}