objective c - SearchBar in NavigationBar -
It is a bit difficult to explain my problem in one sentence, so I will keep two pictures here.
I want this behavior from my app. First I found the simple navigation bar with the buttonbar.
and after the search button it is clicked on me Behavior:
How to obtain this behavior? I got up with only one idea - to create a new scene and move it, but it does not like best practice.
If the search button has right clicked, to hide and show the search bar, I did the following, for example, I took a search bar and once the button items, and the navigation as below Placed in the left and right sides of the bar.
- (zero) viewDidoadload {[Super Viewedload]; UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake (0,0, 250,44)]; SearchBar.placeholder = @ "Search"; UIBarButtonItem * searchBarItem = [[UIBarButtonItem alloc] initWithCustomView: searchBar]; SearchBarItem.tag = 123; SearchBarItem.customView.hidden = Yes; SearchBarItem.customView.alpha = 0.0f; Self.navigationItem.leftBarButtonItem = searchBarItem; UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithTitle: @ "Search" style: UIBarButtonItemStylePlain Target: Self-action: @selector (whenSearchClicked :)]; Self.navigationItem.rightBarButtonItem = leftItem; } - (zero) whenSearchClicked: (id) this {NSArray * buttonsArray = self.navigationController.navigationBar.topItem.leftBarButtonItems; (UIBarButtonItem * item buttons) {if (item.tag == 123 and item.customView.hidden) {item.customView.hidden = NO; If ([item.customView isKindOfClass: [UISearchBar class]]) [item.customViewFirstResponder]; UIBarButtonItem * rightItem = self.navigationController.navigationBar.topItem.rightBarButtonItem; For this example // Single Sanskar Item [rightItem setTitle: @ "Cancel"]; } And {item.customView.hidden = Yes; If ([item.customView isKindOfClass: [UISearchBar class]]) [item.customView resignFirstResponder]; UIBarButtonItem * rightItem = self.navigationController.navigationBar.topItem.rightBarButtonItem; For this example // Single Sanskar item, if u become more than one hav only the array becomes "self.navigationController.navigationBar.topItem.rightBarButtonItems" and set using the tag like [rightItem setTitle: @ "search"]; }}}
Hope this helps
Comments
Post a Comment