在swift中访问navigationController子视图的项
新手到ios应用程序编码在这里,所以任何帮助将不胜感激 我有一个应用程序,当旋转到横向时会自动打开一个侧菜单,我需要它来禁用navigationController子视图中的菜单按钮。这是我的密码 导航控制器在swift中访问navigationController子视图的项,swift,ios8,uinavigationcontroller,swrevealviewcontroller,Swift,Ios8,Uinavigationcontroller,Swrevealviewcontroller,新手到ios应用程序编码在这里,所以任何帮助将不胜感激 我有一个应用程序,当旋转到横向时会自动打开一个侧菜单,我需要它来禁用navigationController子视图中的菜单按钮。这是我的密码 导航控制器 import Foundation class GDNavigationController:UINavigationController{ override func viewWillAppear(animated: Bool) { super.viewWillA
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:")
}
}
我有不同的NavigationController,根据选择的菜单项加载不同的ViewController。不同的NavigationController共享相同的子类,但我不知道加载了哪个viewController,这就是我需要了解的内容以及如何访问该viewController中的按钮
有人能帮忙吗?所以我想出来了,把我的导航控制器换成这个 进口基础 类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
}
}
}