データソースからの結果の表示に問題があります。このコードは、コンソールでは異なる (そして正しい) 結果を表示しますが、シミュレーターではあらゆる種類のランダムながらくたが発生します。
(「results」は、クラスの 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];
}
これは、配列のメモリ保持、または配列内の文字列と関係があるのではないかと思いますか? 私はまだそのコツをつかんでいないのではないかと心配しています。
[Marc 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;
}