0
我有一个最初没有数据的表格,并显示一条消息,指出用户没有要显示的数据。上一个单元格不会在UITableView中消失
我有一个方法被调用viewDidLoad
并重新加载表数据。发生这种情况时,仍会显示第一个表格单元格,其余单元格会显示正确的数据。第一个单元仍然显示空的数据信息。有什么我在这里失踪?下面我有我的cellForRowAtIndexPath
方法。
- (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;
}
当你没有任何数据时,为什么不在你的tableView中添加一个简单的'UILabel',并根据数据的可用性切换它的'hidden'状态?添加到表格视图的任何视图都会随之滚动,并且会给出标签在单元格内的**外观**。这不能回答你的问题,但它确实解决了你的问题。此外,您避免创建第二种类型的单元格。 – n00bProgrammer 2014-09-06 07:04:57
那就是我最终做的。但这不是正确的解决方案......正确的解决方案是弄清楚为什么细胞不会消失。不知道为什么......很奇怪。 – KVISH 2014-09-06 20:43:23