我有一個tableView的部分,可以打開和關閉。所以,當我點擊某個部分打開它時,它會被填滿單元格,並且-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
的調用次數與我在-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
中提供的次數完全相同。tableView:cellForRowAtIndexPath:不僅爲可見細胞調用?
這是正確的嗎?它不應該只是可見細胞的數量嗎?
因爲在我的情況下我有不好的情況:我有很多自定義單元格(50〜100個單元格),並且爲每個單元格調用-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
會減慢部分的打開速度,導致每次從nib讀取都執行,內容正在填充圖像。 我有細胞的檢查知名度內-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
這樣的:
if ([[self.tableView indexPathsForVisibleRows] containsObject:indexPath])
NSLog(@"visible %@", indexPath);
它表明,從45層出來的細胞,只有6或7是可見的。其他人不在可見範圍內。但創建細胞仍然執行。 下面是代碼:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"IVCell";
IVCamera *camera = [server.cameras objectAtIndex:indexPath.row];
IVServerListViewCell *cell = (IVServerListViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"IVServerListCell" owner:self options:nil];
cell = (IVServerListViewCell*)_tableViewCell;
self.tableViewCell = nil;
}
[cell textLabel].text = camera.cameraName;
cell.preview = camera.preview;
cell.userData = camera;
cell.isEnabled = (server.isInactive)?NO:camera.isOnline;
return cell;
}
是否仍然正確?或者我錯過了什麼?
這真棒,我也有這樣的問題,你的技術是如此有用,問題得到解決。 – Ananth 2013-06-11 09:39:42
@Ananth歡迎您! =) – peetonn 2013-06-12 11:44:42