Background: I have UIViewControllerone that, when loaded, has program code UITableViewthat gets its data from the database SQLite3. It works great.
Problem: I need to add UISearchBar(and related logic), but when I try, the UISearcBar is not displayed.
Code:
.h file:
#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 where the UISearchBar is added:
-(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;
NSLog(@"searchBar = %@", searchBar);
NSLog(@"HeaderView = %@", self.tableView.tableHeaderView);
}
What am I doing wrong? What do I need to do to add UISearchBarprogrammatically UITableViewin within UIVewController?
source
share