Ajouter UISearchBar à UITableView par programme ne fonctionne pas

De fond: j'ai un UIViewController que, lorsque les charges, a un UITableView généré par programme qui obtient ses données à partir d'un SQLite3 base de données. Cela fonctionne très bien.

Problème: j'ai besoin d'ajouter un UISearchBar (associée à la logique) mais quand j'essaie, le UISearcBar n'est pas rendu.

Code de la mesure:

.h fichier:

#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "Exhibitor.h"
@interface ExhibitorViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchDisplayDelegate>
{
    sqlite3 *congressDB;
    NSMutableArray *searchData;
    UISearchBar *searchBar;
    UISearchDisplayController *searchDisplayController;
}

@property (strong, nonatomic) IBOutlet UITableView *tableView;

-(NSString *) filePath;
-(void)openDB;

@end

.m le fichier où l'UISearchBar est ajouté:

-(void)loadTableView
{
    CGRect usableSpace = [[UIScreen mainScreen] applicationFrame];
    CGFloat usableWidth = usableSpace.size.width;
    CGFloat usableHeight = usableSpace.size.height;

    UITableView *tableView = [[UITableView alloc] init];
    [tableView setFrame:CGRectMake(0,0,usableWidth, usableHeight)];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 64)];
    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;

    self.tableView.tableHeaderView = searchBar; //I think this should have loaded the searchBar but doesn't

    //[self.tableView setTableHeaderView:searchBar]; //Have also tried this
    //[self.tableView.tableHeaderView addSubview:searchBar];  //And this
    NSLog(@"searchBar = %@", searchBar);  //This shows the searchBar is an object with values
    NSLog(@"HeaderView = %@", self.tableView.tableHeaderView);  //This shows the tableHeaderView as null ?? 

}

Ce que je fais mal? Que dois-je faire pour ajouter un UISearchBar par programme pour un UITableView dans un UIVewController?

OriginalL'auteur Agamemnon | 2014-02-18