xcode - 显示 View 几秒钟(来自 NavController 的自定义推送)

标签 xcode view swift push navigationcontroller

我从主从应用程序开始。现在我尝试添加一个自定义 View (带有简单标签的默认 UIViewController),该 View 将在可访问详细信息/主视图之前显示几秒钟(如加载 View )。
我现在的问题是,如果我将 ViewController 添加到 AppDelegate 并从 NavigationController 推送到它,我会得到一个空 View 。
参见这里:
enter image description here

我没有做任何更改,只是向 appdelegate 添加了一行代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let splitViewController = self.window!.rootViewController as UISplitViewController
    let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as UINavigationController
    navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
    splitViewController.delegate = self

    let masterNavigationController = splitViewController.viewControllers[0] as UINavigationController
    let controller = masterNavigationController.topViewController as MasterViewController
    controller.managedObjectContext = self.managedObjectContext

    // +++ Custom ViewController is to be displayed from here +++

    navigationController.pushViewController(ViewController(), animated: true)

    return true
}

我不明白问题出在哪里......
enter image description here

最佳答案

在代码中使用这一行

navigationController.pushViewController(ViewController(), animated: true)

您正在实例化一个新的空 View Controller ,这可能不是您想要的。

获取对 Storyboard的引用(即从主视图 Controller )以创建 View Controller 并将其推送到导航堆栈上。示例:

if let myVC = controller.storyboard!.instantiateViewControllerWithIdentifier(...) {
    navigationController.pushViewController(myVC, animated: true)
}

关于xcode - 显示 View 几秒钟(来自 NavController 的自定义推送),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26324222/

相关文章:

java - 如何从布局重写 View 的方法?

swift - 如何使用 XCTest 对离线场景进行单元测试

ios - 如何在字段包含字典数组的 firestore 上查询?

objective-c - 访问 super View 属性

macos - 如何在 Swift 中删除一个 View 的所有 subview ?

ios - Ios App如何从后台转到前台

iphone - 在 iPhone SDK 上将图像转换为黑白图像问题

swift - 使用并行运行和 xcodebuild 验证不稳定的 UI 测试

ios - 无法将类型 'CustomProfileCell' 的返回表达式转换为返回类型 'UITableViewCell'

xcode - 如何将焦点设置到 NSButton?