2014-11-21 19 views
0

我有一個表視圖,其中numberOfRowsInSection方法按用戶的需要正確返回。但實際顯示的行數小於numberOfRowsInSection返回的數量。單元格不是靜態的。我沒有對行數設置任何限制。我正在使用故事板,這可能是一個故事板問題。任何線索?ios tableview:行數小於numberOfRowsInSection返回的計數

代碼片段:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

// Return the number of rows in the section. 
if(self.timelineModel){ 
    NSMutableArray *sectionArray = self.timelineModel[self.stepperValue]; 
    NSLog(@"no of rows : %lu",(unsigned long)sectionArray.count); 
    return sectionArray.count; 
} 
else{ 
    return 1; 
} 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
LTTimeLineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableCell" forIndexPath:indexPath]; 

if (cell !=nil){ 
    //some code 
} 

//some code 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
[cell.rowCollView reloadData]; 
NSLog(@"row number : %ld",(long)indexPath.row); 
return cell; 
} 

中出現的日誌:

log 1: 
2014-11-21 17:28:25.937 xx[89937:1095174] no of rows : 6 
2014-11-21 17:28:25.938 xx[89937:1095174] row number : 0 
2014-11-21 17:28:25.939 xx[89937:1095174] row number : 1 
2014-11-21 17:28:25.939 xx[89937:1095174] row number : 2 
2014-11-21 17:28:25.940 xx[89937:1095174] row number : 3 

log 2: 
2014-11-21 17:07:54.932 xx[89937:1095174] no of rows : 5 
2014-11-21 17:07:54.933 xx[89937:1095174] row number : 0 
2014-11-21 17:07:54.933 xx[89937:1095174] row number : 1 
2014-11-21 17:07:54.934 xx[89937:1095174] row number : 2 
2014-11-21 17:07:54.937 xx[89937:1095174] row number : 3 
+0

什麼是「self.timelineModel」和什麼是「self.timelineModel [self.stepperValue]」返回? – 2014-11-21 13:04:01

+0

如果您嘗試向下滾動,會發生什麼情況?它是滾動還是反彈?如果以編程方式向下滾動到第5/6行,這是否有效? – pbasdf 2014-11-21 13:51:03

+0

什麼是rowCollView,你爲什麼需要reloadData? – 2014-11-21 13:59:28

回答

0

這是正常現象。

UITableView中的行是智能加載的,只加載在屏幕上可見的行,其他行將在滾動後加載。

這是因爲alloc(在內存中創建對象)代價高昂。由於這個iOS只創建了幾個單元,然後回收它們。

+0

是的,我明白,但在這種情況下,甚至沒有滾動下來幫助。即使在滾動之後,也不會加載額外的行 – 2014-11-21 12:56:46

+0

但是,在第一次加載表時只有前三個單元格是可見的嗎?因爲從你的日誌中總是會返回3個單元格,而不是單元格的數量。是否有可能numberOfRows再次被調用不同的數字或該委託被更改? – 2014-11-24 05:50:58

相關問題