2014-09-01 67 views
1

我在我的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; 
} 

回答

0

請檢查self.list的指數。它可能開始從1不爲0的N SUInteger row = [indexPath row];

0

就拿你這個代碼:

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

到您的視圖做負載,並保持對細胞產生代表僅分配。

+0

不是。在完成你所建議的內容之後,你可以放心地刪除'if(!cell)'分配塊,因爲返回的單元格永遠不會是'nil'。 – keeshux 2014-09-01 14:51:35

0

可能是因爲佈局限制。確保tableview與屏幕頂部對齊。

相關問題