访问 swift 中的 navigationController 子视图项
Accessing item of a navigationController childview in swift
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:")
}
}
根据选择的菜单项,我有不同的导航控制器加载不同的 viewController。不同的 navigationControllers 共享相同的子类,但我不知道加载了哪个 viewController,这就是我需要找出的以及如何访问 viewController.
中的按钮
有人能帮忙吗?
所以我想通了,把我的导航控制器改成这个
导入基金会
class 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
}
}
}
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:")
}
}
根据选择的菜单项,我有不同的导航控制器加载不同的 viewController。不同的 navigationControllers 共享相同的子类,但我不知道加载了哪个 viewController,这就是我需要找出的以及如何访问 viewController.
中的按钮有人能帮忙吗?
所以我想通了,把我的导航控制器改成这个
导入基金会 class 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
}
}
}