- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中的某个时刻,我需要返回到我的主(即主页)ViewController。所以我需要向后移动到我的导航堆栈,它现在充满了 ViewControllers 和 NavigationControllers。所以我做了以下事情:
// to dismiss the current VC
self.navigationController?.popViewControllerAnimated(true)
// to go back home
UIApplication.sharedApplication().keyWindow?.rootViewController = homeNC
homeNC 是指向 NavigationController 的全局变量,其中包含我的主要“主页”ViewController 的 Storyboard实例。
它有效,但部分有效。意思是,它确实带我回到了我的主 ViewController,但它随后变得对触摸和滚动没有响应。没有任何响应,无论是导航栏按钮还是家庭 NC/VC 中的 TableViewCells。 Xcode 不会崩溃,只是坐在那里等待。
我不知道为什么。谁能想到我在这里缺少什么?
** 编辑 **
可能是因为我在我的主(家庭)VC 中嵌入了一个嵌套的 VC。这是代码以及我之后尝试的其他内容:
homeNC = self.navigationController!
homeVC = self
let discoverVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("DiscoverVC") as UIViewController
// embed discoverVC in this VC
self.addChildViewController(discoverVC)
self.view.addSubview(discoverVC.view)
discoverVC.didMoveToParentViewController(self)
// store self NC for using it by "thank you" VC to come back to home after payment
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
// navigates back but becomes unresponsive
appDelegate.window?.rootViewController = homeVC
// navigates back but becomes unresponsive
appDelegate.window?.rootViewController = homeNC
我还尝试使用以下内容保存对 appdelegate 窗口的引用:
// Initialise sideMenu
window = UIWindow(frame: UIScreen.mainScreen().bounds)
let sideMenu = SSASideMenu(contentViewController: UINavigationController(rootViewController: MainViewController()), leftMenuViewController: LeftMenuViewController())
window!.rootViewController = sideMenu
window!.makeKeyAndVisible()
// get a reference to appdelegate's window so that we can navigate back later
mainWindow = window!
但是当我这样做时它又不会导航回来:
appDelegate.window?.rootViewController = mainWindow.rootViewController
最佳答案
试试这个。我会为你工作。
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = mainVC
编辑
我读出了您编辑过的问题。 SSASideMenu
出现问题。我更新了我的答案,我希望它现在对你有用。您必须进行两项更改。首先在 AppDelegate.swift
中,像这样设置 SSASideMenu
的属性:
var window: UIWindow?
var sideMenu: SSASideMenu!
现在您的代码将更改为:
sideMenu = SSASideMenu(contentViewController: UINavigationController(rootViewController: MainViewController()), leftMenuViewController: LeftMenuViewController())
现在如果你想改变 View Controller ,你必须像这样改变 SSASideMenu
的 contentViewController
:
func showDiscoverVC() {
//Instantiate ViewController
let discoverVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("DiscoverVC") as UIViewController
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.sideMenu.contentViewController = UINavigationController(rootViewController: discoverVC)
}
关于ios - UIApplication.sharedApplication().keyWindow?.rootViewController 卡住了我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34860996/
谁能帮我理解以下两行之间的区别: [UIApplication.sharedApplication.delegate.window addSubview:myView]; [UIApplication
我刚刚从 XCode 6.4 升级到 Xcode 7 GM 并开始更改代码以符合 Swift 2。我无法克服以下错误。 该项目是一个键盘扩展,片段来自包含的应用程序。 let s = "htt
当使用 SharedApplication.openUrl 打开例如iOS 上的邮件程序,该应用程序在邮件程序打开的同时隐藏。 有什么办法可以让应用程序保持在后台吗?那么当用户存在邮件程序时,它会返回
我目前正在为 iPad 应用程序开发“设备内”(而非模拟器)监控系统。系统应该能够执行以下操作: -用户输入模拟:模拟用户输入:点击、拖动、键盘。 -信息记忆:输入后得到文本值和结果。 此信息稍后将报
嗯,我有这两个变量,一个 NSString 和一个 NSMutable 数组,我希望在所有选项卡中将其值设为全局值。到目前为止我只有一个(NSString)并且我可以正常获取它的值。不,我尝试再添加一
我有一个带有按钮的 subview ,点击它会打开 map 和位置。代码没有错误,但是一旦我被发送到 map 并返回我的应用程序……它会再次打开 map 。所以我猜这个方法被调用了两次。我该如何阻止它
下面的代码工作正常,但是当我回到我的应用程序时,它继续执行下面的代码,但我不知道为什么以及如何停止它。我认为这只发生在 ios5.0 中:应用流程 - rootviewcontroller -> ma
我在使用 3D Touch 动态快速操作快捷方式时遇到了一个非常简单的问题。 我希望在应用程序终止时清除快捷方式(通过双击主页按钮并向上滑动)。 我调用 UIApplication.sharedApp
我使用框架在我的主应用程序和 Today Extension 之间共享通用代码。我经常遇到以下情况:我试图访问从我的框架运行的 UIApplication.sharedApplication()(主应
我正在尝试从 UIViewController 获取对我的应用程序委托(delegate)的引用,但我不断收到此错误消息: 'sharedApplication()' is unavailable:
为什么没有在 MonoTouch 中实现 SharedApplication 的 TerminateWithSuccess 方法?我怎样才能调用它?或者更好的是,我如何以编程方式关闭应用程序? 最佳答
我正在使用 [[UIApplication sharedApplication] delegate] 在多个类之间共享变量。我在 AppDelegate 中设置了该值。我可以从 myAppDelega
我正在尝试测试(使用 XCTest 框架)驻留在框架(动态库)内的 View Controller 。我遇到了属性 UIApplication.sharedApplication().keyWindo
在处理 Objective-C 时, 我需要得到 protectedDataAvailable状态可能在一些后台线程中。 - (BOOL) isProtected { BOOL protect
我有一个测试项目可以在多个 View Controller 上使用私有(private)数据对象。(我是从网络和 git-hub 下载的) - (ExampleAppDataObject*) theA
我想知道在通过您的应用程序的 URL 启动后,是否仍然可以从 iOS 系统应用程序接收状态或回调,例如: 用户打开我的应用程序-->点击 FaceTime URL FaceTime 已打开并开始响铃-
我正在阅读有关为支持 3dTouch 的设备的主屏幕添加动态快捷方式的信息。它本质上归结为读/写 shortcutItems UIApplication.sharedApplication 的成员数组
我正在尝试访问一个创建导航 Controller 的变量,该导航 Controller 是我在 View Controller 中的 App Delegate 中定义的(我正在为每个选项卡构建一个带有
尝试访问我的 AppDelegate 实例但因 swift_dynamicCastClassUnconditional 而失败。 class AppDelegate: UIResponder, UIA
我正在尝试制作一个表格单元格,当点击它时会调用电话号码,我认为我必须使用的代码是; [[UIApplication sharedApplication] openURL:[NSURL URLWithS
我是一名优秀的程序员,十分优秀!