2012-03-16 25 views
0

私は標準のUISearchBarを持つテーブルビューコントローラを持っていますUISearchBarDelegateとUITableViewが連携していませんか?

テーブルの最初の行を入力時に検索バーのテキストに置きたいと思います。 私はこれが働くだろうと思ったが、それはしていません:

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 
    // results is a mutable array with an empty string at index 0 
    [[self results] replaceObjectAtIndex:0 withObject:searchText]; 
    [[self tableView] reloadData]; 
} 

私はそれが正しくオブジェクト、 を交換され、コンソールに結果の配列を記録している場合、それは、テーブルビューによってピックアップ取得されていません。またはは、insertObject::私はちょうどinsertObjectAtIndexを使用する場合は

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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 

    [[cell textLabel] setText:[[self results] objectAtIndex:[indexPath row]]]; 

    return cell; 
} 

:それは結果を示してい

は私が通常通り設定テーブルのデータソースを持っています。私が最初のオブジェクトを置き換えようとしていないときだけ。 お願いします! :)

+0

この行を削除してみてください。 'if(cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } '。私が言うのは、あなたが各セルを割り当てているということです。 – Gobot

+0

私は離れて隠していた投稿です:http://stackoverflow.com/questions/2286669/iphone-how-to-purge-a-cached-uitableviewcell – Gobot

答えて

0

[OK]を、それを考え出しました。 本当に愚かすぎる.... searchBarはtableViewの最初の行をカバーしていたので、更新がわかりませんでした。 Doh。

-1

if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }この殺害を試みてください。私が言うのは、あなたが各セルを割り当てているということです。

ここで私は離れて隠していたポストです:iPhone: How to purge a cached UITableViewCell

+0

私はリロードデータを呼び出します! – Cameron

+0

ええ、私はちょうどそれを見た、ごめんなさい – Gobot

+0

どのようにあなたのtableviewデータソースデリゲートメソッドを実装していますか? – Gobot

-1

あなたは、このような検索テーブルビューをリロードしてみてください:

[self.searchDisplayController.searchResultsTableView reloadData]; 
+0

私はsearchDisplayControllerを使用していません – Cameron

関連する問題