iOS 7 doesn't show cancel button of search bar in navigation bar

后端 未结 8 1222
情书的邮戳
情书的邮戳 2021-02-04 02:47

In an app that\'s supposed to run on iOS 6 and iOS 7, the cancel button of the search bar embedded in the navigation bar is not shown anymore if the app is run on iOS 7. On iOS

相关标签:
8条回答
  • 2021-02-04 03:31

    I've solved this problem simple, just by adding rightBarButtonItem :)

    self.navigationItem.titleView = self.searchBar;
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel", nil) style:UIBarButtonItemStylePlain target:self action:@selector(didClickCancelButton:)] autorelease];
    

    But sure you have to check if current iOS version is >= 7.0, otherwise you will get two "cancel" buttons..

    BTW This method allows you to have "cancel" button which always enabled

    0 讨论(0)
  • 2021-02-04 03:35

    iOS 7 is different with iOS 6 in navigation bar, so if you want to show UISearch bar in navigation bar,you can try this:

    put your UISearchbar on a UIView like this[self.searchView addSubview self.searchBar], and set the navigationbar's titleView to your searchView like thisself.navagitioncontroller.navigationItem.titleView = self.searchView

    Hope it works for you

    0 讨论(0)
提交回复
热议问题