开发者

Adding UISearchBar programatically - Bar is Off Screen at Launch - iPad

I have added a UISearchBar to a table in my iPad app using the below code. The table is on the left hand side of my split view contro开发者_运维百科ller.

The problem is that when the app starts the search bar is strangely off screen to the left - you can just see the last few pixels of it. If you click on it, or scroll down and back up, it reverts itself and looks like it should.

Can anyone suggest how to fix this ?

Thanks

searchBar = [[UISearchBar alloc] init];
self.tableView.tableHeaderView = searchBar;

searchController = [[UISearchDisplayController alloc]
                    initWithSearchBar:searchBar
                    contentsController:self];

searchBar.delegate = self;
searchController.delegate = self;
searchController.searchResultsDelegate=self;
searchController.searchResultsDataSource=self;


You can try to create the UISearchBar with a frame like:

 CGRect searchViewFrame = CGRectMake(33, 33, 264, 31);

or whatever dimensions or origin.

Like other resource, you can create the UISearchBar within a UIView, and add this UIView to the UITableView:

UIView *containerSearch = [[UIView alloc] initWithFrame: searchViewFrame];
searchBar = [[UISearchBar alloc] init];
[containerSearch addSubview: searchBar];
self.tableView.tableHeaderView = containerSearch;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜