這裏是一個Xcode項目,我只是做了問這個問題:的UITableViewDelegate方法
http://www.mediafire.com/?z26ufsfhby62br9
打開日誌並運行它。您會發現它輸出display: x
和create: x
,其中x是一個數字0到49並且對應於相同數字的單元格。在執行任何滾動操作之前,它應該只輸出到22,因爲Apple總是吹噓自己的桌面視圖是根據需要加載的。
它基本上顯示,幾乎一出現tableview就爲每個單元格觸發了tableView:willDisplayCell:forRowAtIndexPath:
和tableView:cellForRowAtIndexPath:
,爲什麼?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"create: %i", indexPath.row);
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row];
return cell;
}
- (void) tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"display: %i", indexPath.row);
}
爲什麼在tableView加載後(以及在每個單元格出現之前)調用上述meothds?當然,他們應該在每個細胞出現之前才被調用?
當我運行它而沒有觸及任何東西時,只顯示前23行(從0到22),日誌確認只有23個單元格被創建並顯示。這是模擬器,4.2,最新的SDK。 – Costique 2010-12-13 17:34:05
由於某些原因,只有當模擬器是活動窗口時纔會啓動。 – 2010-12-13 17:52:16
我從你的代碼中添加了上述方法。 – vikingosegundo 2010-12-14 01:08:30