質問

私は、データソースからの結果を表示するといくつかの問題を抱えています。このコードは、コンソール内の別の(と正しい)結果を示すが、シミュレータでランダムながらくたのすべての種類になります。

( "結果" がクラスの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;
}
役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top