【问题标题】:Accessing item of a navigationController childview in swift快速访问navigationController子视图的项目
【发布时间】:2015-09-06 03:15:57
【问题描述】:

ios 应用程序编码新手在这里,任何帮助将不胜感激。

我有一个应用程序,当旋转到横向时会自动打开一个侧边菜单,我需要它来禁用 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:")
    }  
}

根据选择的菜单项,我有不同的导航控制器加载不同的视图控制器。不同的导航控制器共享同一个子类,但我不知道加载了哪个视图控制器,这是我需要找出的以及如何访问该视图控制器中的按钮。

谁能帮忙?

【问题讨论】:

    标签: swift ios8 uinavigationcontroller swrevealviewcontroller


    【解决方案1】:

    所以我想通了,把我的导航控制器改成这个

    导入基础 类 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
        }
    
    }
    

    }

    【讨论】:

      猜你喜欢
      • 2016-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多