UISearchBar disappears when switching views with UISegmentControl

I have a UISearchBar (& UISearchDisplayController) inside the sidebar of the tableView that I created (see attached photo). This is visible when a button is clicked in my UINavigationBar. Inside my map controller, I have a UISegmentControl in the navigation bar that allows my user to switch between views (mapView and friendsMapView).

enter image description here

For some reason, the UISearchBar appears just in the sidebar when it is initially open. However, when I switch the segment control to switch to friendsMapView, and then back to mapView, my UISearchBar disappeared (see photo).

enter image description here

Any idea why this could be? I implemented above in StoryBoard. See below the code for the control segment (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]; } 
+6
source share
1 answer

I donโ€™t know your current view controller, but it seems that you are installing a new navigation controller below and your current viewcontroller navigation panel has a search panel, but the new navigation controller does not.

 UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:menuController]; [self.revealViewController setRearViewController:nc]; 
+2
source

Source: https://habr.com/ru/post/1013102/


All Articles