IOS:为什么我的tableview的第一行是空白的?
我在TableViewCell中定义了一些标签,并让程序将NSDictionary中的信息读入单元格。但是当我运行它时,我的tableview的第一行是空白的,其余行的显示是正常的。 我尝试使用NSLog来捕获传递到单元格的内容,结果与NSLog字典中的内容相同。 错在哪里 以下是我的部分代码:IOS:为什么我的tableview的第一行是空白的?,ios,Ios,我在TableViewCell中定义了一些标签,并让程序将NSDictionary中的信息读入单元格。但是当我运行它时,我的tableview的第一行是空白的,其余行的显示是正常的。 我尝试使用NSLog来捕获传递到单元格的内容,结果与NSLog字典中的内容相同。 错在哪里 以下是我的部分代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat
- (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;
}
请检查
自我列表的索引。它可能从NSUInteger行=[indexPath行]中的1而不是0开始代码>拿着你的代码:
UINib*nib=[UINib nibWithNibName:@“外卖”捆绑包:无];
[表视图注册表项nb:nib forCellReuseIdentifier:TableSampleIdentifier];
在您的视图中,只加载并保留单元格创建委托上的分配。可能是,这是因为布局限制。确保表视图与屏幕顶部对齐。不完全对齐。按照您的建议执行后,您可以安全地摆脱if(!cell)
分配块,因为返回的单元格永远不会是nil
。