Reputation: 681
I am trying to convert a iphone app to universal app, here is my code
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
// self.viewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
[self.window addSubview:self.viewController.view];
[self.timer invalidate];
self.timer = nil;
self.timer = [NSTimer scheduledTimerWithTimeInterval: 3 target: self selector: @selector (pullnextview) userInfo: nil repeats: YES];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
[self.window addSubview:self.viewController.view];
[self.timer invalidate];
self.timer = nil;
self.timer = [NSTimer scheduledTimerWithTimeInterval: 3 target: self selector: @selector (Ipadpullnextview) userInfo: nil repeats: YES];
}
==================================================================================
-(void)pullnextview
{
[self.viewController.view removeFromSuperview];
[self.timer invalidate];
self.timer = nil;
NSArray *viewsArray;
//create the first view controller
SearchViewController *navController0 = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
navController0.tabBarItem.image = [UIImage imageNamed:@"search.png"];
[navController0 setTitle:@"Neuen Termin buchen"];
//create the navigation controller and use NavRootController as its root
UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:navController0];
UINavigationController *nav;
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
int uid = [standardUserDefaults integerForKey:@"dmloginid"];
[standardUserDefaults synchronize];
if(uid>0)
{
SearchViewController *navController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
[navController setTitle:@"Meine Termine"];
nav = [[UINavigationController alloc] initWithRootViewController:navController];
}
else
{
LoginViewController *navController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
[navController setTitle:@"Meine Termine"];
nav = [[UINavigationController alloc] initWithRootViewController:navController];
}
SettingsViewController *navController3 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
navController3.tabBarItem.image = [UIImage imageNamed:@"setting.png"];
[navController3 setTitle:@"Einstellungen"];
//create the navigation controller and use NavRootController as its root
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:navController3];
viewsArray = [NSArray arrayWithObjects:nav0,nav,nav3, nil];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0,0,320,460);
//then tell the tabbarcontroller to use our array of views
[tabbarController setViewControllers:viewsArray];
//then the last step is to add the our tabbarcontroller as subview of the window
self.window.rootViewController = tabbarController;
}
-(void)Ipadpullnextview
{
[self.viewController.view removeFromSuperview];
[self.timer invalidate];
self.timer = nil;
NSArray *viewsArray;
//create the first view controller
SearchViewController *navController0 = [[SearchViewController alloc] initWithNibName:@"IpadSearchViewController" bundle:nil];
navController0.tabBarItem.image = [UIImage imageNamed:@"search.png"];
[navController0 setTitle:@"Neuen Termin buchen"];
//create the navigation controller and use NavRootController as its root
UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:navController0];
UINavigationController *nav;
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
int uid = [standardUserDefaults integerForKey:@"dmloginid"];
[standardUserDefaults synchronize];
if(uid>0)
{
SearchViewController *navController = [[SearchViewController alloc] initWithNibName:@"IpadSearchViewController" bundle:nil];
navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
[navController setTitle:@"Meine Termine"];
nav = [[UINavigationController alloc] initWithRootViewController:navController];
}
else
{
LoginViewController *navController = [[LoginViewController alloc] initWithNibName:@"IpadLoginViewController" bundle:nil];
navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
[navController setTitle:@"Meine Termine"];
nav = [[UINavigationController alloc] initWithRootViewController:navController];
}
SettingsViewController *navController3 = [[SettingsViewController alloc] initWithNibName:@"IpadSettingsViewController" bundle:nil];
navController3.tabBarItem.image = [UIImage imageNamed:@"setting.png"];
[navController3 setTitle:@"Einstellungen"];
//create the navigation controller and use NavRootController as its root
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:navController3];
viewsArray = [NSArray arrayWithObjects:nav0,nav,nav3, nil];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0,0,320,460);
//then tell the tabbarcontroller to use our array of views
[tabbarController setViewControllers:viewsArray];
//then the last step is to add the our tabbarcontroller as subview of the window
self.window.rootViewController = tabbarController;
}
==================================================================================
I am calling the two different function containing the same code but the .xib is different . After that when i went to run the code this error is coming.
==================================================================================
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "IpadSearchViewController" nib but the view outlet was not set.'
Can anyone help me. I am new in this section.
Upvotes: 0
Views: 762
Reputation: 4249
Go to your IPad XIB and connnect the view outlet by right clicking the view and then connecting the referencing outlet of view to file owner..It shall work fine
Upvotes: 3