2013-07-17 100 views
6

我正在使用故事板,如下图所示,我正面临错误我的代码已成功执行,但它们没有页面显示或模拟器中的操作仅在启动图像后显示黑屏。以编程方式显示故事板视图

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; 
} 

错误

这个错误时,我没有选择的切入点在storybroad是初始我面对查看Controll呃。

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 

错误

此错误当我选择storybroad切入点,我面对的是初始视图控制器(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' 
+0

你的故事板是如何设置的?导航控制器是初始控制器吗?它的根视图控制器是什么? – rdelmar

+0

您可以使用一些错误检查来查看故事板和视图是否成功返回。此外,'(UINavigationController *)self.window.rootViewController'看起来可疑,应该测试。 – Jenn

+0

我不明白我是如何设置故事板和什么是导航控制器的初始控制器?请告诉我如何知道根视图控制器?解释它并请解决我的问题。 –

回答

5

顺便说一句,我知道你已经解决了你的问题,但我只是想建议另一个流程。或者,您可以始终从标准的初始场景开始(您可以在应用程序代理中不使用任何代码的情况下执行此操作),但可以通过其viewWillAppear确定是否需要条款和条件(T & C),如果有,单独的场景模式(动画或不动画,如你所见)。您可以让用户确认T & C然后解除条款和条件场景,您将回到标准的“初始”场景。

如果你这样做,你的T & C将被解雇,你不需要玩编程改变rootViewController,导航控制器的顶层场景总是作为标准的“初始”场景所以像popToRootViewController这样的东西没有任何轻微的工作,您不必隐藏T页面上的导航栏等等。它也适用于您可能会向用户显示看到T & C(例如,如果您有合适的地方可以展示它,请将其隐藏在“设置”或“关于”场景中)。

如果你想知道如何以编程方式去与T & C,你可以定义从您最初的场景SEGUE到T & C情景:

create segue

然后选择SEGUE并给它的标识:

segue identifier

现在你的初始场景的viewWillAppear可能performSegueWithIdentifier,如:

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

    BOOL hasAcceptedTermsAndConditions = ...; 

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

我很高兴你解决了你的问题,但我只是想建议一个替代流程。

0

好的可能的原因是,您可能错过了将身份检查器中的类/控制器名称分配给storyBoard中的控制器。接下来在你的plist文件中检查一下你是否有故事板条目的专题名称。

希望这个工程。 :)

4

终于解决了我的问题,我用这个代码

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]; 
相关问题