UIPopoverController里面的UISearchBar继续点击

时间:2013-10-29 22:28:03

标签: ios objective-c ios7 uisearchbar uitoolbar

我目前正在尝试在弹出窗口中放置一个表格视图和搜索栏,但我得到一个非常奇怪的错误。每当我点击搜索栏时,取消按钮都会激活,并且栏会立即降低状态栏的大小。

Normal State

When Selected

我尝试过使用UIBarPosition代理,但这也没有做任何事情。我已经尝试了所有我能想到的东西,所以我想我会问你的帮助。这是我在UITableViewController中使用的代码,用于将搜索栏添加到表头:

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];

if (self)
{

    searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, popoverWidth, singleRowHeight)];
    searchBar.delegate = self;
    searchBar.showsScopeBar= YES;

    searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplayController.delegate = self;
    searchDisplayController.searchResultsDataSource = self;
    searchDisplayController.searchResultsDelegate = self;
    searchDisplayController.searchResultsTableView.rowHeight = singleRowHeight;
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.tableView.tableHeaderView = searchBar;

    return self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
    return UIBarPositionTop;
}

谢谢!

1 个答案:

答案 0 :(得分:2)

根据Extra space above search bar when UISearchDisplayController is active

- (void)viewDidLoad {
   [super viewDidLoad];

    if ([self respondsToSelector:@selector(edgesForExtendedLayout:)]) { /// iOS 7 or above
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
}