2016-12-12 42 views
6

我在創建的tableView側欄內有一個UISearchBar(& UISearchDisplayController)(請參閱附圖)。當我的UINavigationBar中的按鈕被點擊時它是可見的。在我的Map View Controller內部,我在導航欄中有一個UISegmentControl,它允許我的用戶在視圖之間來回切換(mapView & friendsMapView)。當使用UISegmentControl切換視圖時,UISearchBar消失

enter image description here

出於某種原因,在的UISearchBar側欄時,它最初打開出現就好了。但是,當我點擊段控制切換到friendsMapView,然後回到mapView,我的UISearchBar消失了(見圖)。

enter image description here

任何想法,這可能是爲什麼?我已經在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]; 



} 
+0

您可能只想根據選擇的segmentedControl選項來顯示/隱藏'mapView'和'friendsMapView'。我不知道爲什麼每次用戶選擇'segmentedControl'選項時都要更改'revealViewController'的'rearViewController'? – Adeel

+0

@Adeel因爲當顯示friendsMapView時,在側邊欄中可以看到不同的菜單(當顯示mapView時顯示一個菜單,當顯示friendsMapView時顯示不同的菜單)。 – Brittany

+0

您提供的信息恐怕不夠。請分享您設置爲後視控制器的視圖控制器。你有沒有做過任何調試?請分享你對這個問題的發現。 – Adeel

回答

2

我不知道你當前的ViewController但似乎你在下面設置一個新的navigationcontroller和當前視圖 - 控制的導航欄有搜索欄,但新的導航控制器沒有。

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

你是100%的權利 - 因爲當我評論這些行時,搜索工作就很好。那麼我應該簡單地在另一個tableview中進行搜索嗎? – Brittany

+1

這是一種方式,但我看到你有一個容器視圖控制器,你正在改變此控制器內的視圖控制器。因此,如果您想更改主佈局,只需將viewcontroller的視圖添加到容器視圖即可。它通過搜索欄保存當前導航欄。在revealViewcontroller裏面你可以使用'[self.view addSubview:CHANGED_VIEWCONTROLLER.view];' – abdullahselek

+0

@Brittany你能接受我的回答嗎? – abdullahselek

相關問題