0
我用UINavigationController添加了UISearchBar和UISearchDisplayController。因爲我們在navigationBar中需要幾個按鈕,所以我創建了一個包含幾個按鈕的自定義視圖,並將其作爲rightBarButtonItem。我注意到當我點擊搜索欄時,鍵盤從底部彈出,並且還將UINavigationController的導航條從屏幕上移開。所以現在我看不到我在UISearchBar中輸入的內容。有沒有辦法解決這個問題?我看過其他應用程序,它們看起來像在導航條的LHS或RHS上使用UINavigationBar +多個按鈕,所以我認爲這是可能的。謝謝。帶UINavigationController的UISearchBar
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIImage *house = [UIImage imageNamed:@"icon_house.png"];
[homeButton setImage:house forState:UIControlStateNormal];
[homeButton addTarget:self action:@selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:@"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:@selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.SearchEntry = [[[UISearchBar alloc] initWithFrame:CGRectMake(98, 0, 150, 44)] autorelease];
self.SearchEntry.delegate = self;
UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:_searchEntry contentsController:self];
searchDisplayCtlr.searchResultsDataSource = self;
searchDisplayCtlr.searchResultsDelegate = self;
searchDisplayCtlr.delegate = self;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];
[containerView addSubview:homeButton];
[containerView addSubview:filterButton];
[containerView addSubview:_searchEntry];