上一个单元格未在UITableView中消失

上一个单元格未在UITableView中消失,uitableview,Uitableview,我有一个最初没有数据的表,它显示了一个UITableViewCell,其中有一条消息说用户没有数据要显示 我有一个方法,在viewDidLoad上被调用并重新加载表数据。发生这种情况时,第一个表格单元格仍会显示,其余单元格将在其下方显示正确的数据。第一个单元格仍然显示空数据消息。这里有我遗漏的东西吗?下面是我的cellforrowatinexpath方法 - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath tab

我有一个最初没有数据的表,它显示了一个
UITableViewCell
,其中有一条消息说用户没有数据要显示

我有一个方法,在
viewDidLoad
上被调用并重新加载表数据。发生这种情况时,第一个表格单元格仍会显示,其余单元格将在其下方显示正确的数据。第一个单元格仍然显示空数据消息。这里有我遗漏的东西吗?下面是我的
cellforrowatinexpath
方法

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView {
    static NSString *CellIdentifier = @"TableViewCell";
    static NSString *CellIdentifierEmpty = @"TableViewCellEmpty";

    if ([[self.fetchedResultsController.sections objectAtIndex:indexPath.section] numberOfObjects] == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEmpty];
        if(cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifierEmpty];
            cell.backgroundColor = [UIColor whiteColor];
            cell.textLabel.textColor = [UIColor blackColor];

            cell.detailTextLabel.numberOfLines = 0;
            cell.detailTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
            cell.detailTextLabel.textColor = [UIColor blackColor];
            cell.tag = -1;
        }
        return [self setTextForEmptyCell:cell];
    }

    MyObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = // Set values
    }
    // Set cell details        
    return cell;
}

发现了问题。使用
AFNetworking
从服务器获取数据时出现线程问题。检查正在使用新线程的所有块

如果没有任何数据,为什么不在tableView中添加一个简单的
UILabel
,并根据数据的可用性切换它的
隐藏状态,而不是使用单元格?任何添加到表视图的视图都会随之滚动,并显示标签在单元格内。这并不能回答你的问题,但它确实解决了你的问题。另外,你要避免创建第二种类型的单元格,这就是我最后要做的。但这不是正确的解决方案。。。正确的解决办法是找出为什么细胞不会消失。不知道为什么…很奇怪。