2
我想了解每個單元格的渲染是如何工作的。這裏是我的代碼:tableView cellForRowAtIndexPath最初調用多次
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"QuestionCell";
static NSString *cellNib = @"QuestionsTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellNib owner:self options:nil];
cell = [nib objectAtIndex:0];
NSLog(@"%@", @"--> load from nib");
}
return cell;
}
該代碼中的NSLog最初被調用8次(因爲我最初有8行可見)。然後,當我開始滾動時,它會被調用一次,之後不會再被調用。我認爲它應該被調用過一次,因爲它應該在第一次調用之後重新使用它?爲什麼在最初的8次之後再次調用? (抓頭...)
uncomment'// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];'Line,然後再次檢查 – rptwsthi
@rptwsthi我使用IB的「標識符」字段來做到這一點。 – pixelfreak