0
私のtableviewは正常に動作しており、問題なくすべてのデータをロードしています。 didSelectRowAtIndexPath
を使用して問題が発生し、セルのチェックボックスを追加/削除します。私は最初の10のセルをチェックし、スクロールして、タップしなかったセルのチェックボックスを表示します。なぜ私はインタラクションとスクロール中にUITableViewでメモリリークが発生するのですか?
この問題の原因は何ですか?以下は私のテーブルビューのコードです。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = @"reuseCellForFilter";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Category *category = [self.categories objectAtIndex:indexPath.row];
cell.textLabel.text = category.title;
return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.categories.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@", indexPath);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Category *category = [self.categories objectAtIndex:indexPath.row];
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.titles addObject:category];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
for (Category *categoryID in [self.titles reverseObjectEnumerator]) {
if (categoryID.categoryID == category.categoryID) {
[self.titles removeObject:categoryID];
}
}
}
}
(categoryID.categoryID == category.categoryID)がポインタ型の変数に対して正しく動作するかどうかを確認してください。 – heximal