0
我在导航栏内放置了一个搜索栏。这里是代码NavigationBar中的UISearchBar在键盘显示时出现偏差
self.navigationBar =[[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
[self.view addSubview:self.navigationBar];
self.doneButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneButtonPressed)];
self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];
self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.searchBar.placeholder = @"Name of City";
self.searchBar.delegate = self;
self.searchController = [[UISearchDisplayController alloc]initWithSearchBar:self.searchBar contentsController:self];
self.searchController.delegate = self;
self.searchController.searchResultsDelegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsTitle = @"Add Location";
self.searchController.displaysSearchBarInNavigationBar = YES;
self.searchController.navigationItem.rightBarButtonItems = @[self.doneButton];
self.navigationBar.items = @[self.searchController.navigationItem];
但搜索栏的行为不正确。
我希望它看起来像这样
定义后“不正确“ –
@ElGuapo搜索框不在前面。我更新了问题,添加了预期的UI。 – fengd
这是Sol吗?在查看代码时我看到了同样的问题。 :D –