0

私は理由もなくNSMutableArray私に与えるという問題に直面しています。Exc_Bad_Access

約 700 のレコードを含むがありUITableViewます。フィルター プロセスを有効にしたいのですが、次の方法を使用して のコンテンツをフィルター処理していますUITableView

- (void) filterTableContentWith:(int)_minValue andWith:(int)_maxValue {

       [tableContent removeAllObjects];
       tableContent = [[NSMutableArray alloc] initWithArray:originalTableContent copyItems:YES];

       if (_minValue == 0 && _maxValue == 0) {
            NSLog(@"This is mean that no filter is activate here");
       } else {
            for (int x = ([tableContent count] - 1); x >= 0; x--) {
                 if ([[[tableContent objectAtIndex:x] objectForKey:@"price"] intValue] < _minValue && [[[tableContent objectAtIndex:x] objectForKey:@"price"] intValue] > _maxValue) {
                       [tableContent removeObjectAtIndex:x];
                 }
            }
       }
       NSLog(@"tableContent count = %@",[tableContent count]);
       [self.tableView reloadData];
}

このメソッドを呼び出すとExc_Bad_AccessNSLog(@"tableContent count ...

[tableContent removeAllObjects];それは配列を解放していると思いますが、それは不合理です。

どんな助けでも大歓迎です。

4

2 に答える 2

3

countを返すintので、次のように変更NSLogします。

NSLog(@"tableContent count = %d",[tableContent count]);

そして、あなたは大丈夫でしょう。

于 2012-05-20T00:20:25.453 に答える
0

NSLogのカウントを%dで変更することに加えて、ループ内のコンテンツを削除するよりも、次のコードの方が優れていると思います。

...
} else {
  NSPredicate* predicate = [NSPredicate predicateWithFormat:
    @"price < %d AND price > %d", _minValue, _maxValue];
  NSArray* array = [tableContent filteredArrayUsingPredicate:predicate];
  tableContent = array;
}
...
于 2012-05-20T00:40:48.850 に答える