简体   繁体   English

进行布尔运算的正确方法是什么?

[英]What is the correct way to proceed with this bool?

I have this bool in my AppDelegate.m: 我的AppDelegate.m中有以下布尔值:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

        UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];

        self.window.rootViewController = viewController;
        [self.window makeKeyAndVisible];

        return YES;
    }

I'm getting an error on the *storyboard but what I am mainly trying to do is initialize the application in a different view controller than the main one. 我在* storyboard上遇到错误,但是我主要想做的是在与主视图控制器不同的视图控制器中初始化应用程序。 I have all the view controllers with IDs (such as the one I want to launch is named "Home"). 我有所有带有ID的视图控制器(例如我要启动的一个名为“ Home”的视图控制器)。 How would I correctly write this bool if say my ViewController ID was home? 如果说我的ViewController ID在家,我将如何正确编写此bool?

My main.m: 我的main.m:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

The nil I get is whenever I try to go back to the original Home page from my Contact list page so it crashes and highlights the nil line. 我得到的nil是每当我尝试从“联系人”列表页面返回原始主页时,它崩溃并突出显示nil行。 Both this and the above delegate bool are giving me issues. 这和上面的代表布尔都给我带来了问题。 Any clarification would be very much appreciated, thanks. 任何澄清将不胜感激,谢谢。

Use this in your AppDelegate.m 在您的AppDelegate.m中使用它

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];



    HomeController *viewController = // initialise it 

    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

or in the storyBoard just put the pointing arror to the view controller which you want to make as a root view controller. 或在storyBoard中,只需将指向错误的指针放到要作为根视图控制器创建的视图控制器上即可。

The stack trace explains what's wrong: 堆栈跟踪说明了问题所在:

  • Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MainStoryboard' in bundle NSBundle (loaded)' * 由于未捕获的异常“ NSInvalidArgumentException”而终止应用程序,原因:“在捆绑包NSBundle中已找到名为“ MainStoryboard”的故事板(已加载)” *

Your storyboard isn't called "MainStoryboard". 您的情节提要板不称为“ MainStoryboard”。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM