代表方法不会在搜索结果表上触发

时间:2012-06-28 11:33:18

标签: ios5 uitableview uisearchdisplaycontroller uisearchbardelegate

所有

我有一个带有详细信息的UITableView,带有一个从代码创建的搜索栏。适用于所选项目,但从搜索结果中单击项目时不起作用;没有代表方法开火。之前从未见过这种行为所以我不知道问题出在哪里。

我对标准表格单元格以及自定义表格单元格有相同的行为。

感谢任何指导,谢谢。

只是挂在这里 enter image description here

//ViewController.h
 @interface SongsViewController : UITableViewController <UISearchBarDelegate,UISearchDisplayDelegate>
{
   NSMutableArray *searchData;
   UISearchBar *searchBar;
   UISearchDisplayController *searchDisplayController;
   UITableViewCell *customSongCell;
 }




 //ViewController.m
 -(void)viewDidLoad
 {
    [super viewDidLoad];

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 88)];

   [searchBar setShowsScopeBar:YES];
   [searchBar setScopeButtonTitles:[[NSArray alloc] initWithObjects:@"Title",@"Style", nil]];

   searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
   searchDisplayController.delegate = self;
   searchDisplayController.searchResultsDataSource = self;
   self.tableView.tableHeaderView = searchBar; 

   //Load custom table cell
    UINib *songCellNib = [UINib nibWithNibName:@"SongItem" bundle:nil];

  //Register this nib, which contains the cell
  [[self tableView] registerNib:songCellNib forCellReuseIdentifier:@"SongItemCell"];

  // create a filtered list that will contain products for the search results table.
  SongStore *ps = [SongStore defaultStore];
  NSArray *songObjects = [ps allSongs];

  self.filteredListContent = [NSMutableArray arrayWithCapacity: [songObjects count]];
  self.masterSongArr = [[NSMutableArray alloc] initWithArray:[ps allSongs]];

 [self refreshData];

 [self.tableView reloadData];
 self.tableView.scrollEnabled = YES;

}

1 个答案:

答案 0 :(得分:4)

我解决了这个问题。我忘了设置这个searchDisplayController委托:

[searchDisplayController setSearchResultsDelegate:self];

因此,请务必设置全部

searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
[searchDisplayController setSearchResultsDelegate:self];