2009-03-31 12 views
0

データソースの結果を表示する際に問題が発生します。このコードでは、コンソールには異なる結果が表示されますが、シミュレータにはあらゆる種類のランダムなクラップスが発生します。Cocoa Touch tableデータソースの問題

(「結果」クラスのNSMutableArrayのプロパティがあります。)私は、これはメモリアレイの保持、または配列内の文字列とは何かを持っているかもしれないと推測している

-(void) handleSearchForKeywords: (NSString *) keywords { 
    [results removeAllObjects]; 
    int r = rand() % 10; 
    for(int i = 0; i < r; i++) { 
     [results addObject:[NSString stringWithFormat:@"test %i: %@", i, keywords]]; 
    } 
    [self reloadTheTable]; 
} 

-(void) reloadTheTable { 
    NSLog(@"current array contents: %@", results); 
    [tableView reloadData]; 
}

?私はまだそれが掛かっていないのではないかと心配しています。

[マークBesseyに応じて編集 - 私はここにすべてがあなたの基本的なデータソースの方法だと思う]

-(NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section { 
    return [results count]; 
} 

-(UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { 
    static NSString *SearchViewControllerCell = @"SearchViewControllerCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SearchViewControllerCell]; 
    if(cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero reuseIdentifier: SearchViewControllerCell] autorelease]; 
     NSUInteger row = [indexPath row]; 
     [cell setText:[results objectAtIndex:row]]; 
    } 
    return cell; 
}

答えて

1

私はこの問題は、あなたが投稿したコードではないと思います。テーブルビューのデータソースを実装するコードのほうが可能性が高いです。

+0

あなたは正しいです。セルのテキストを設定していたビットは、キャッシュループ内にありました。 if(cell == nil){ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:blah] autorelease]; [セルのsetText:[結果objectAtIndex:行]]; } ^間違っています –

関連する問題