简体   繁体   中英

Programmatically displaying Storyboard view

I am using Storyboard that i am facing error as shown in below my code is successfully executed but their is no page show or action in simulator only show black screen after launching image.

ClsMainPageAppDelegate.h

#import <UIKit/UIKit.h>

@interface ClsMainPageAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

ClsMainPageAppDelegate.m

#import "ClsMainPageAppDelegate.h"
#import "ClsMainPageViewController.h"
#import "ClsTermsandConditionViewController.h"

@implementation ClsMainPageAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.


NSUserDefaults *fetchDefaults = [NSUserDefaults standardUserDefaults];
int message = [fetchDefaults integerForKey:@"checkvalue"];
NSLog(@"Message Hello : %i",message);

if(message == 1)
{

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ClsMainPageViewController *mvc = [storyboard instantiateViewControllerWithIdentifier:@"BeIinformedPage"];
    [(UINavigationController*)self.window.rootViewController pushViewController:mvc animated:NO];
    NSLog(@"Launched Home Page");


}
else
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ClsTermsandConditionViewController *mvc = [storyboard instantiateViewControllerWithIdentifier:@"termsandConditionControl"];
    [(UINavigationController*)self.window.rootViewController pushViewController:mvc animated:NO];
    NSLog(@"Launched Terms and Conditions Page");
}
return YES;
}

Error

This error i face when i am not choose entry point in storybroad is Initial View Controller.

2013-07-17 19:38:12.749 BeInformed[1011:c07] Failed to instantiate the default view
controller for UIMainStoryboardFile 'MainStoryboard' - perhaps the designated entry
point is not set?
2013-07-17 19:38:16.127 BeInformed[1011:c07] Message Hello : 0
2013-07-17 19:38:18.333 BeInformed[1011:c07] Launched Terms and Conditions Page

Error

This error i face when i am choose entry point in storybroad is Initial View Controller (termsandConditionControl)

 2013-07-17 19:53:19.839 BeInformed[1057:c07] Message Hello : 0
 2013-07-17 19:53:26.175 BeInformed[1057:c07] - [ClsTermsandConditionViewController
 pushViewController:animated:]: unrecognized selector sent to instance 0x71b2f50
 2013-07-17 19:53:26.176 BeInformed[1057:c07] *** Terminating app due to uncaught 
 exception 'NSInvalidArgumentException', reason: '-[ClsTermsandConditionViewController  
 pushViewController:animated:]: unrecognized selector sent to instance 0x71b2f50'

By the way, I know you've solved your issue, but I just wanted to suggest another flow. You could, alternatively, always start with your standard initial scene (which you can do without any code in the app delegate), but have its viewWillAppear determine if you need the terms and conditions (T&C), and if so, present that separate scene modally (either animated or not animated, as you see fit). You can have the user's confirmation of the T&C then dismiss the terms and conditions scene and you'll be back at the standard "initial" scene.

If you do it that way, your T&C will be dismissed, you don't have to play around with changing the rootViewController programmatically, the top level scene of the navigation controller always stays as the standard "initial" scene so things like popToRootViewController work without any slight of hand, you don't have to hide the navigation bar on the T&C page, etc. It also lends itself to a flow where you might present the user an option of seeing the T&C again (eg buried on the "settings" or "about" scenes, if you have an appropriate place to show it).

And if you're wondering how to programmatically go to T&C, you could define a segue from your initial scene to the T&C scene:

创造segue

Then select that segue and give it an identifier:

segue标识符

And now your initial scene's viewWillAppear could performSegueWithIdentifier , such as:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    BOOL hasAcceptedTermsAndConditions = ...;

    if (!hasAcceptedTermsAndConditions)
    {
        [self performSegueWithIdentifier:@"TermsAndConditions" sender:self];
    }
}

I'm glad you solved your issue, but I just wanted to suggest an alternative flow.

Finally solved my Problem , i used this Code

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    ClsTermsandConditionViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"termsandConditionControl"];
    UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:ivc];
    self.window.rootViewController=nil;
    self.window.rootViewController = navigationController;
    [navigationController setNavigationBarHidden:YES];
    [self.window makeKeyAndVisible];

Ok The possible reason is, you might have missed out assigning Class/controller name in the identity inspector to your controller in storyBoard. Next also have a check in your plist file that you have storyboard entry with proper name of your storyboard.

Hope this works. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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