2012-05-12 8 views
0

私はページをロードする上で200個のオブジェクトを持つ配列を持っています。これらの(可変コピー)をfiltersArrayというテンポラリ配列にコピーし、それを次にuitableviewで表示します。これはすべてうまく動作します:)uitableview配列の内容が失われています

これは、選択されたときに、予測とフィルター処理された配列を使用して元の配列をフィルタリングすることになっているセグメントセレクタを持っています。これはうまく働いています:)

私はステップスルーが最初のカップルのオブジェクトのために働いているように見える私のテーブルビュー(again with filteredarray)を再読み込みしようとしましたが、その後filterarrayは "空"テーブルがリフレッシュされた直後に、正しい単語と私のコードがクラッシュします。私はそれがメモリの問題か何かでなければならないと確信しています。私はかなり客観的なCに新しいので、どんな助けも大歓迎です。私はあなたがNSMutableArrayのを持っているので、私はfilterUsingPredicate:代わりのfilteredArrayUsingPredicate:を使用することをお勧めし

- (void)viewDidLoad 
{ 
[super viewDidLoad];  
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
filteredArray = [appDelegate.originalArray mutableCopy];  
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *cellidentifier = @"customcell"; 
customcell *cell = (customcell *)[tableView dequeueReusableCellWithIdentifier: 
            cellidentifier]; 
array_details *arrayObj = [filteredArray objectAtIndex:indexPath.row]; 

// UITableViewCell cell needs creating for this UITableView row. 
if (cell == nil) 
{ 
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil]; 

    for (id currentObject in topLevelObjects) { 
     if ([currentObject isKindOfClass:[customcell class]]) { 
      cell = (customcell *) currentObject; 
      break; 
     } 
    } 
} 


    cell.line1.text = arrayObj.line1; 
    cell.line2.text = arrayObj.line2; 
return cell; 
} 


-(IBAction)change_segment:(id)sender;{ 
if(segmentcontrol.selectedSegmentIndex == 2){ 
    filteredArray = [appDelegate.originalArray mutableCopy];  
    NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"selected == YES"]; 
    filteredArray = [filteredArray filteredArrayUsingPredicate:testForTrue]; 
} 

[my_table reloadData]; // its when i do this that the array filtered array seems to somehow get "emptied" 

以下の私のコードの一部を列挙されているし、私のfilteredarrayはnsmutable配列

NSMutableArray *filteredArray; 

答えて

1

としてmy.hファイルで宣言されています。あなたがコピーを介して取得するので、あなたが最初にフィルターをかけた配列は保持されますが、あなたのchange_segment:メソッドで置き換えられた配列はそうではありません。

(I 容疑者が、これは問題ではなく、クラッシュの詳細であり、その関連する例外は診断が容易になります。)

+0

フィリップ、もし私があなたのことを示唆しているのであれば... filterUsingPredicate:次に、 "MSMutableArray * 'に' VOIDの互換性のない型から 'を代入しています。 – user1096447

+0

'filterUsingPredicate:'メソッドは何も返しません。それは単に受信機に作用する。だからあなたは結果を割り当てません。 –

+0

ありがとうフィリップは治療をしました! – user1096447

0

あなたの配列を保持しています。 -deallocでリリースします。

filteredArray = [appDelegate.originalArray mutableCopy] retain];

+0

私は 'mutableCopy'は' alloc'と同じように既に保持されているオブジェクトを返すと信じています。だから、彼はARCを使用していないと仮定すると、すでにカウントが増えているはずです...しかし、あなたが言うように、リリースは良いアイデアです! –

関連する問題