[英]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. 我正在使用Storyboard,我正面临着错误,如下所示,我的代码已成功执行,但它们没有页面显示或模拟器中的操作仅在启动图像后显示黑屏。
ClsMainPageAppDelegate.h ClsMainPageAppDelegate.h
#import <UIKit/UIKit.h>
@interface ClsMainPageAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
ClsMainPageAppDelegate.m 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. 当我不在storybroad中选择入口点时,我面临的这个错误是初始视图控制器。
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) 当我在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'
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). 或者,您可以始终从标准的初始场景开始(您可以在应用程序委托中没有任何代码的情况下执行),但让viewWillAppear
确定您是否需要条款和条件(T&C),如果需要,则显示单独的场景模态(动画或不动画,如你所见)。 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. 您可以让用户确认T&C然后关闭条款和条件场景,您将回到标准的“初始”场景。
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). 如果你这样做,你的T&C将被解雇,你不必以编程方式更改rootViewController
,导航控制器的顶级场景始终保持标准的“初始”场景,所以像popToRootViewController
这样的东西popToRootViewController
工作任何轻微的手,你不必隐藏T&C页面上的导航栏等。它也适用于一个流程,你可以向用户呈现再次看到T&C的选项(例如埋在“设置”上)或“约”场景,如果你有一个合适的地方来展示它)。
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: 如果您想知道如何以编程方式转到T&C,您可以定义从初始场景到T&C场景的segue:
Then select that segue and give it an identifier: 然后选择segue并给它一个标识符:
And now your initial scene's viewWillAppear
could performSegueWithIdentifier
, such as: 现在你的初始场景的viewWillAppear
可以执行performSegueWithIdentifier
,例如:
- (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. 确定可能的原因是,您可能错过了在身份检查器中将类/控制器名称分配给storyBoard中的控制器。 Next also have a check in your plist file that you have storyboard entry with proper name of your storyboard. 接下来还要检查plist文件中是否有故事板条目以及故事板的正确名称。
Hope this works. 希望这有效。 :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.