0

新手到ios應用程序編碼在這裏,所以任何幫助將不勝感激。在swift中訪問navigationController子視圖的項目

我有一個應用程序,當旋轉到風景自動打開一個側面菜單,我需要它來禁用導航控制器的子視圖中的菜單按鈕。這是我的代碼。

導航控制器

import Foundation 
class GDNavigationController:UINavigationController{ 
    override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 
     //Send notification when the device is rotated. 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil) 
    } 

    func rotated(){ 
     /* 
     Put the code here to access the menu button 
     */ 
     if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)) 
     { 
      //disable the menu button here 
      self.revealViewController().setFrontViewPosition(FrontViewPosition.Right, animated: false) 
     } 

     if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) 
     { 
      //enable the menu button here 
      self.revealViewController().setFrontViewPosition(FrontViewPosition.Left, animated: false) 
     } 
    } 
} 

我的ViewController代碼

import Foundation 
class LocalCollectionController: UICollectionViewController{  
    @IBOutlet var MenuViewButton: UIBarButtonItem! 
    override func viewDidLoad() { 
     MenuViewButton.target = self.revealViewController() 
     MenuViewButton.action = Selector("revealToggle:") 
    } 
} 

我有基於哪一個菜單項被選擇在不同的viewControllers不同navigationControllers負載。不同的navigationControllers共享相同的子類,但我永遠不知道哪個viewController被加載,這是我需要找出並如何訪問該viewController中的按鈕。

任何人都可以幫忙嗎?

回答

0

所以我想通了,我的導航控制器改變這種

進口基金會 類GDNavigationController:UINavigationController的{

var BBItem = UIBarButtonItem() 
override func viewDidAppear(animated: Bool) { 
    BBItem = self.topViewController.navigationItem.leftBarButtonItem! 

} 

override func viewWillAppear(animated: Bool) { 
    super.viewWillAppear(animated) 
    //Send notification when the device is rotated. 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil) 
    self.rotated() 
} 


func rotated(){ 

    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)) 
    { 
     self.revealViewController().setFrontViewPosition(FrontViewPosition.Right, animated: true) 
     self.BBItem.enabled = false 
    } 

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)) 
    { 
     self.revealViewController().setFrontViewPosition(FrontViewPosition.Left, animated: true) 
     self.BBItem.enabled = true 
    } 

} 

}