我正在开发一个屏幕,我想根据condition.ie加载视图控制器,应用程序启动时来自应用程序委托的特定视图控制器类。如何在应用程序启动时从应用程序委托加载不同的视图控制器类(例如,从应用程序委托)
if(condition success)
{
//Load viewcontroller1
} else
{
//Load viewcontroller2
}
我怎样才能做到这一点。请帮我..
我正在开发一个屏幕,我想根据condition.ie加载视图控制器,应用程序启动时来自应用程序委托的特定视图控制器类。如何在应用程序启动时从应用程序委托加载不同的视图控制器类(例如,从应用程序委托)
if(condition success)
{
//Load viewcontroller1
} else
{
//Load viewcontroller2
}
我怎样才能做到这一点。请帮我..
只需打开Xcode中,创建一个新的项目,使其通用(iPad/iPhone的),你会看到的一个例子这个。它会为您创建两个.xib文件。一个用于iPad,一个用于iPhone。
然后,应用程序委托执行此:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
在这种情况下,它使用两个.xibs相同ViewController
类(ViewController.h和.M)。但是,你当然也可以改变这一点。只需进入Xcode图形设计器中的每个.xib(以前称为Interface Builder),选择.xib,选择文件的所有者,然后在Inspector选项卡(属性...通常在右边),您可以选择一个自定义类别从组合框中。
所以,如果你需要一个不同的Objective-C UIViewController
子类,你可以这样做。请记住更改上面的代码以匹配([ViewController alloc]
)。
您可以看到Apple完成的操作。创建通用应用程序。在appDelegate中,您可以看到
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
} else {
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
}
根据条件,它们加载不同的视图控制器。
[如何用指定的UIViewController启动应用程序?不与第一个](http://stackoverflow.com/questions/6898917/how-to-start-the-app-with-the-uiviewcontroller-specified-not-with-the-first) – 2012-07-23 05:48:40