Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'
like image 900
Rahul Saini Avatar asked Jul 17 '13 14:07

Rahul Saini


People also ask

Should I use storyboard or programmatically?

I recommend getting comfortable using Storyboard as well as designing programmatically so that you can decide which method to use on a project-by-project basis. If you have an urge to create a static UI and are a solo developer, Storyboard is probably the best option.

How do I add views to my storyboard?

In storyboards, you add views by dragging them onto the view controller scene. For example, the following figure shows a view controller with an image view and button on an iPhone.


1 Answers

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 (e.g. 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:

create segue

Then select that segue and give it an identifier:

segue identifier

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.

like image 95
Rob Avatar answered Sep 29 '22 01:09

Rob