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日後にもう一度呼び出されますか? (スクラッチヘッド...)
コメントを外します。// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; '改行してもう一度チェックしてください。 – rptwsthi
@rptwsthi私はIBの" Identifier "フィールドを使ってこれを行います。 – pixelfreak