Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS:为什么我的tableview的第一行是空白的?_Ios - Fatal编程技术网

IOS:为什么我的tableview的第一行是空白的?

IOS:为什么我的tableview的第一行是空白的?,ios,Ios,我在TableViewCell中定义了一些标签,并让程序将NSDictionary中的信息读入单元格。但是当我运行它时,我的tableview的第一行是空白的,其余行的显示是正常的。 我尝试使用NSLog来捕获传递到单元格的内容,结果与NSLog字典中的内容相同。 错在哪里 以下是我的部分代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPat

我在TableViewCell中定义了一些标签,并让程序将NSDictionary中的信息读入单元格。但是当我运行它时,我的tableview的第一行是空白的,其余行的显示是正常的。 我尝试使用NSLog来捕获传递到单元格的内容,结果与NSLog字典中的内容相同。 错在哪里

以下是我的部分代码:

- (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;
}

请检查
自我列表的索引。它可能从N
SUInteger行=[indexPath行]中的1而不是0开始

拿着你的代码:


UINib*nib=[UINib nibWithNibName:@“外卖”捆绑包:无];
[表视图注册表项nb:nib forCellReuseIdentifier:TableSampleIdentifier];


在您的视图中,只加载并保留单元格创建委托上的分配。

可能是,这是因为布局限制。确保
表视图与屏幕顶部对齐。

不完全对齐。按照您的建议执行后,您可以安全地摆脱
if(!cell)
分配块,因为返回的单元格永远不会是
nil