プログラムでコンテンツを表示する UITableView があります。
セルは最初に開いたときに正常に読み込まれますが、スクロールするとすべて同じキャプションが表示されます。これは、最後のセルのキャプションであると思います。
セルが選択されている場合に開く基になる TableView は引き続き正常に機能します。
私はSOで解決策を調べましたが、それらは私にとってはうまくいかなかったか、私が愚かすぎて問題を理解できませんでした。これは、ある種のリソースを節約するためにセルを再利用しているようです。
問題がそこにあると想定しているため、cellForRowAtIndexPath を投稿します。さらにコードが必要な場合はお知らせください。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString *oneLine = [entrys objectAtIndex:position];
NSArray *lineComponents = [oneLine componentsSeparatedByString:@";"];
cell.textLabel.text = [lineComponents objectAtIndex:0];
cell.textLabel.textColor = [UIColor colorWithRed:0.0 green:0.8 blue:0.2 alpha:1.0];
if (position < [entrys count] -2 ) {
position++;
}
return cell;
}
前もって感謝します