私は標準の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;
}
:それは結果を示してい
は私が通常通り設定テーブルのデータソースを持っています。私が最初のオブジェクトを置き換えようとしていないときだけ。 お願いします! :)
この行を削除してみてください。 'if(cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } '。私が言うのは、あなたが各セルを割り当てているということです。 – Gobot
私は離れて隠していた投稿です:http://stackoverflow.com/questions/2286669/iphone-how-to-purge-a-cached-uitableviewcell – Gobot