繁体   English   中英

iOS:为什么我的表格视图的第一行是空白的?

[英]IOS: why the first row of my tableview was blank?

我在TableViewCell中定义了一些标签,并使程序将NSDictionary中的信息读取到单元格中。 但是当我运行它时,tableview的第一行为空白,其余各行的显示均正常。 我尝试使用NSLog捕获传递到单元的内容,答案与NSDictionary中的内容相同。 哪里可能错了?

这是我的代码的一部分:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *TableSampleIdentifier = @"TableSampleIdentifier";

     TakeAwayCell *cell = [tableView dequeueReusableCellWithIdentifier: TableSampleIdentifier];

     if (!cell)
     {
         cell = [ [TakeAwayCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableSampleIdentifier];   //'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'error without this line

         UINib *nib = [UINib nibWithNibName:@"TakeAwayCell" bundle:nil];
         [tableView registerNib:nib forCellReuseIdentifier:TableSampleIdentifier];
     }

     NSUInteger row = [indexPath row];

     cell.image = self.list[row][@"image"];
     cell.name = self.list[row][@"name"];
     cell.addr = self.list[row][@"addr"];

     NSLog(@"%@",cell.name);

     return cell;
}

请检查self.list索引。 它可能从N SUInteger row = [indexPath row]; 1而不是0开始SUInteger row = [indexPath row];

使用您的以下代码:

UINib *nib = [UINib nibWithNibName:@"TakeAwayCell" bundle:nil]; [tableView registerNib:nib forCellReuseIdentifier:TableSampleIdentifier];

在您看来,确实加载并仅在单元格创建委托上保留分配。

可能是因为布局限制。 确保tableview与屏幕顶部对齐。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM