我有一个位于表视图侧边栏中的 UISearchBar(和 UISearchDisplayController),如所附照片所示。当我的 UINavigationBar 中的按钮被点击时,它变得可见。在我的地图视图控制器中,我在导航栏中使用了一个 UISegmentControl,允许用户在视图之间切换(mapView 和 friendsMapView)。
由于某种原因,当初始打开时,UISearchBar在侧边栏中显示得很好。但是当我点击分段控件切换到friendsMapView,然后返回到mapView时,我的UISearchBar消失了(见照片)。
你知道这是为什么吗?我已经在StoryBoard中实现了上述内容。请参考下面的segmentControl代码(不确定是否有帮助):
.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];
}
segmentedControl
选项的选择来显示/隐藏mapView
和friendsMapView
。我不确定为什么每次用户从segmentedControl
中选择一个选项时,你都要更改revealViewController
的rearViewController
? - Adeel Miraj