[indexPath 行] とスクロールについて他にも多くの質問があることは承知していますが、奇妙な数値が返される理由を理解できる人はいますか? セルを構成した方法の回避策を見つけられないようです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProfileIdentifier";
NSUInteger row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
//My custom xib file is named "ProfileCell.xib"
[[NSBundle mainBundle] loadNibNamed:@"ProfileCell" owner:self options:nil];
cell = profileCell;
self.profileCell = nil;
}
//name and info are both of type NSArray
labelName.text = [name objectAtIndex:row];
labelInfo.text = [info objectAtIndex:row];
NSLog(@"Row: %d", row);
return cell;
}
コンソールはロード時にこれを返します:
2012-08-26 09:09:10.966 Nav[8028:f803] 行: 0
2012-08-26 09:09:10.983 Nav[8028:f803] 行: 1
2012-08-26 09:09:10.986 Nav[8028:f803] 行: 2
2012-08-26 09:09:10.996 Nav[8028:f803] 行: 3
2012-08-26 09:09:10.999 Nav[8028:f803] 行: 4
2012-08-26 09:09:11.002 Nav[8028:f803] 行: 5
2012-08-26 09:09:11.004 Nav[8028:f803] 行: 6
2012-08-26 09:09:11.007 Nav[8028:f803] 行: 7
2012-08-26 09:09:11.010 Nav[8028:f803] 行: 8
2012-08-26 09:09:11.012 Nav[8028:f803] 行: 9
次に、画面外のセルまでスクロールすると、これが返されます。
2012-08-26 09:09:12.354 Nav[8028:f803] 行: 3
2012-08-26 09:09:12.404 Nav[8028:f803] 行: 2
2012-08-26 09:09:12.471 Nav[8028:f803] 行: 1
2012-08-26 09:09:12.622 Nav[8028:f803] 行: 0
ユーザーがスクロールするたびに、私の labelName.text と labelInfo.text が変化しています。
ただし、影響を受けるセルは一番下のセルだけです。9 番目のセルの labelName を [indexPath 行] と一致させるにはどうすればよいですか?