简体   繁体   English

如何在应用加载时使viewController出现?

[英]How do I make a viewController appear when app loads?

I've got a working app that doesn't crash and I've set my initial VC to be the one I want. 我有一个不会崩溃的可正常运行的应用程序,并且已将我的初始VC设置为我想要的。 When running on the simulator, my app opens for the first time on the VC I want, but if I go to; 在模拟器上运行时,我的应用程序将在我想要的VC上第一次打开,但是如果我要打开的话; Hardware -> Home and click on the app again on the main iPhone menu, the app loads the VC I left with and not the VC I set an my main. 硬件->主页,然后再次在iPhone主菜单上单击该应用程序,该应用程序将加载我剩下的VC,而不是我设置主菜单的VC。 I'm new to iOS development so I don't understand what's not working. 我是iOS开发的新手,所以我不明白什么是行不通的。 Other questions's answers don't help me a bit since my main VC is set on my storyboard. 其他问题的答案对我的主VC设置在情节提要上没有任何帮助。 Thanks for the help guys! 感谢您的帮助! This is in my appDelegate file: 这是在我的appDelegate文件中:

func applicationWillResignActive(application: UIApplication) {

    NSNotificationCenter.defaultCenter().addObserver(self, selector:"appWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)

    func appWillResignActive() -> () {
        self.navigationController?.popToViewController(ViewController, animated: false)
    }
}

You can subscribe to the UIApplicationWillResignActiveNotification and call a method right before the app goes to the background, to set the VC to the one you want. 您可以订阅UIApplicationWillResignActiveNotification并在应用程序进入后台之前调用方法,以将VC设置为所需的VC。 This way, once they re-open the app, it should be where you want it to be. 这样,一旦他们重新打开应用程序,它就应该在您想要的位置。

Obj-C: 对象:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];

-(void) appWillResignActive {
    [self.navigationController popToViewController:<UIViewController you want> animated:NO];
}

SWIFT: 迅速:

NSNotificationCenter.defaultCenter().addObserver(self, selector:"appWillResignActive", name:UIApplicationWillResignActiveNotification, object: nil)

func appWillResignActive() -> () {
    self.navigationController.popToViewController(<UIViewController you want>, animated: false)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在应用程序加载时使视图首先出现(3个视图中)-iOS - How to make a view appear first when the app loads up, out of 3 views - IOS 导出图标以进行即席分发时,如何使我的图标出现在IOS PhoneGap应用程序上? - How do I make my Icon appear on my IOS PhoneGap app when I export it for adhoc distribution? 在制作没有ViewController的应用程序时如何使用RootViewController? - How do I use a RootViewController when making an app without a ViewController? 单击单元格时,ViewController出现两次 - Viewcontroller appear twice when I click cell 当我在app didFinishLaunchingWithOptions中收到UIApplicationLaunchOptionsLocationKey时,我是否初始化viewController? - Do I initialize the viewController when I receive UIApplicationLaunchOptionsLocationKey in app didFinishLaunchingWithOptions? 如何使我们的iOS应用作为书签显示在Facebook的新iOS应用(10月发布)中? - How do I make our iOS app appear as a bookmark in Facebook's new iOS app (released October)? NSUserDefaults 问题(如何在启动应用程序时需要时打开不同的 viewController) - NSUserDefaults Question (how do i open a different viewController when needed while starting the app) 应用首次加载时,如何使用隐式动画为图层设置动画? - How do I use implicit animation to animate a layer when the app first loads? 我想在TAB加载另一个ViewController时立即执行操作 - I want to immediately execute things when TAB loads another ViewController 轻按视图时,如何显示键盘并开始编辑文本字段 - How do I make the keyboard appear and the text field begin editing when the view is tapped
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM