私のアプリの UITableViewController は、json データ ソースからデータを取得します。また、CG を使用してカスタム UITableViewCell 背景を作成しました。発生する非常に興味深いバグがあり、その理由はわかりません。何が起こるか、どのように再現するかについて説明します。
タップしてテーブル ビューに入ります。テーブルをまったくスクロールせずに、ビュー内のアイテムをすぐにタップします。その項目をタップした後、戻るボタンを押してテーブル ビューに戻ります。次に、画面外から表示される最初のセルを下にスクロールすると、カスタム背景がありません。これは、セルのデフォルトになります。次に、10 番目のセルごとに下にスクロールし続けると、同じ問題が発生します。
このバグは、この正確なプロセスでのみ発生します。アイテムをタップする前にテーブルビューをスクロールしても、それは起こりません。
テーブルビュー コントローラーに関連するコードは次のとおりです。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Will remove all of the used codes from the table if setting is enabled
if (self.shouldHideCodes) {
NSMutableArray *tempArray = [self.jsonCodeData mutableCopy];
[tempArray removeObjectsInArray:[self.usedCodes usedCodes]];
self.jsonCodeData = tempArray;
}
return [self.jsonCodeData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (self.jsonCodeData) {
cell = [tableView dequeueReusableCellWithIdentifier:@"code cell"];
if ([cell isKindOfClass:[CodeCellTVC class]]) {
CodeCellTVC *tvcCell = (CodeCellTVC *)cell;
if (![tvcCell.backgroundView isKindOfClass:[CustomCellBackground class]]) {
tvcCell.backgroundView = [[CustomCellBackground alloc] init];
}
NSDictionary *codeDict = [self.jsonCodeData objectAtIndex:indexPath.row];
// Retrieve code string from dictionary
NSString *codeText = [NSString stringWithFormat:@"%@", [codeDict objectForKey:@"code"]];
tvcCell.codeTableLabel.text = codeText;
}
}
return cell;
}
私を混乱させるのは、それがどのように反応するかです。バグが発生すると、すべてのセルではなく、10 番目のセルごとに問題が発生します。これらのメソッド以外に、tableviewcell 自体を処理するものはありません。