Saturday, March 18, 2017

UISearchBar disappears when switching views with UISegmentControl

Leave a Comment

I have a UISearchBar (& UISearchDisplayController) inside of a tableView side bar that I created (see photo attached). It is visible when a button in my UINavigationBar is tapped. Inside of my Map View Controller, I have a UISegmentControl in the navigation bar that allows my user to switch back and forth between views (mapView & friendsMapView).

enter image description here

For some reason, the UISearchBar appears just fine in the side bar when it is initially opened. However when I tap segment control to switch to friendsMapView, and then go back to mapView, my UISearchBar is gone (see photo).

enter image description here

Any idea why this could be? I've implemented the above in StoryBoard. See segmentControl code below (not sure if this helps):

.m

-(IBAction)segmentControl:(id)sender {     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];     UITableViewController *menuController;      menuController = [storyBoard instantiateViewControllerWithIdentifier:@"neighbourMenu"];     self.title = @"Controller 1";      switch (self.segmentControl.selectedSegmentIndex)     {          case 0:            [mapView setHidden:NO];             [friendsMapView setHidden:YES];               menuController = [storyBoard instantiateViewControllerWithIdentifier:@"neighbourMenu"];               break;            case 1: //FRIENDS MAP VIEW               menuController = [storyBoard instantiateViewControllerWithIdentifier:@"FriendMenu"];           //  self.title = @"Item 1";              [mapView setHidden:YES];             [friendsMapView setHidden:NO];               //FRIENDS MAPVIEW LOCATION/ZOOM              friendsMapView.delegate = self;             self.locationManager = [[CLLocationManager alloc] init];             self.locationManager.delegate = self;    #ifdef __IPHONE_8_0             if(IS_OS_8_OR_LATER) {                    [self.locationManager requestWhenInUseAuthorization];                 //     [self.locationManager requestAlwaysAuthorization];             } #endif             [self.locationManager startUpdatingLocation];               friendsMapView.showsUserLocation = YES;             [friendsMapView setMapType:MKMapTypeStandard];             [friendsMapView setZoomEnabled:YES];             [friendsMapView setScrollEnabled:YES];              break;            case 2:              [mapView setHidden:YES];             [friendsMapView setHidden:YES];              break;       }      UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:menuController];     [self.revealViewController setRearViewController:nc];    } 

1 Answers

Answers 1

I don't know your current viewcontroller but it seems you are setting a new navigationcontroller at below and your current viewcontroller's navigation bar has the search bar but the new navigationcontroller does not.

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:menuController]; [self.revealViewController setRearViewController:nc]; 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment