2013-07-17 102 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]; 
相關問題