我在我的TableViewCell中定義了一些標籤,並讓我的程序從NSDictionary中讀取信息到單元中。但是當我運行它時,我的tableview的第一行是空白的,其餘行的顯示是正常的。 我試圖用NSLog來捕捉傳遞給單元格的內容,答案與NSDictionary中的內容相同。 哪裏可能出錯?IOS:爲什麼我的tableview的第一行是空白的?
這裏是我的代碼部分:
- (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;
}
不是。在完成你所建議的內容之後,你可以放心地刪除'if(!cell)'分配塊,因爲返回的單元格永遠不會是'nil'。 – keeshux 2014-09-01 14:51:35