This is what i am doing in my application:
in my appDelegate.m file ,
//Four Views
@synthesize fvc;
@synthesize svc;
@synthesize tvc;
@synthesize pvc;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
NSString *name1,*name2,*name3;
name1 = NSLocalizedString(@"home", nil);
name2 = NSLocalizedString(@"quote", nil);
name3 = NSLocalizedString(@"ship", nil);
UITabBarController *tabBar = [[UITabBarController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
//[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
tvc = [storyboard instantiateViewControllerWithIdentifier:@"thirdview"];
fvc = [storyboard instantiateViewControllerWithIdentifier:@"firstview"];
svc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
pvc =[storyboard instantiateViewControllerWithIdentifier:@"PayViewController"];
fvc.tabBarItem.title = name1;
fvc.tabBarItem.image = [UIImage imageNamed:@"home.png"];
fvc.tabBarItem.titlePositionAdjustment = UIOffsetMake(2.0, 0);
tvc.tabBarItem.title = name2;
tvc.tabBarItem.image = [UIImage imageNamed:@"ping.png"];
tvc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, 2.0);
svc.tabBarItem.title = name3;
svc.tabBarItem.image = [UIImage imageNamed:@"zoom.png"];
svc.tabBarItem.titlePositionAdjustment = UIOffsetMake(-5.0, 0);
NSLog(@"appdelegate %@ and %@",svc,svc.title);
tabBar.viewControllers = [NSArray arrayWithObjects:fvc,svc,tvc,nil];
// the below line does not allow [self.navigationController pushViewController:svNew animated:YES]; to function
self.window.rootViewController = tabBar;
// Override point for customization after application launch.
return YES;
In my fvc view im performing change view operation in okPressed method:
- (IBAction)okPressed:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
SecondViewController *svNew = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
[self.navigationController pushViewController:svNew animated:YES];
}
When i comment the code in the appdelegate method the switching between the views thru the okPressed method is executed successfully. But when I uncomment the appDelegate method it does not perform switching. What i found out was , the code in appdelegate method “self.window.rootViewController = tabBar;” is the culprit. Can anyone guide me on this.
I think you should embed your UITabBarController in a Navigation Controller to make it work:
and then
Otherwise you can’t push anything since you probably got no UINavigationController to push things to!