Good day. I try to add new tab with navigation controller to my app. I create a new tabbed app (xcode 4.2) and in appdelegate write this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
NavController *navController = [[[NavController alloc] initWithNibName:#"NavController" bundle:nil] autorelease]; //my controller
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, navController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
NavController.h file
#interface NavController : UINavigationController
#end
Here the structure of project
And when I run project it show me empty tab
But in xib file I add lable and buttons
May be I forgot something?
Initialise your navigation controller with some UIViewController that is :
RootViewController *rootViewController = [[[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil] autorelease];
NavController *navController = [[[NavController alloc] initWithRootViewController: rootViewController] autorelease];
This might help.
i am sharing you my APP Code about this feature,Hope this can solve your Problem easily
Add this code in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *localNavigationController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:3];
viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[localControllersArray addObject:localNavigationController];
AlaramClock *aAlaramClock = [[[AlaramClock alloc] initWithNibName:#"AlaramClock" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aAlaramClock];
[localControllersArray addObject:localNavigationController];
CurrentTime *aCurrentTime = [[[CurrentTime alloc] initWithNibName:#"CurrentTime" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aCurrentTime];
[localControllersArray addObject:localNavigationController];
Settings *aSettings = [[[Settings alloc] initWithNibName:#"Settings" bundle:nil] autorelease];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:aSettings];
[localControllersArray addObject:localNavigationController];
tabBarController.viewControllers = localControllersArray;
[localControllersArray release];
// Override point for customization after app launch
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
Then U will get this look
after this in Every ViewController.m
ADD this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
// Custom initialization
self.title=#"Calculate Time";
self.tabBarItem.title = #"Calculate Time";
self.tabBarItem.image=[UIImage imageNamed:#"time_calculate.png"];
}
return self;
}
Related
My app has a first page containing a UITabBarController and tabBar.
But when I pushViewController to UINavigationController , my UITabBarController is not showing.
appdelegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:#"anasayfaViewController" bundle:nil];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:#"SehirRehberiViewController" bundle:nil];
duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:#"duyuruViewController" bundle:nil];
sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:#"sikayetViewController" bundle:nil];
digerViewController *diger = [[digerViewController alloc] initWithNibName:#"digerViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[firstTab,sehirRehberi,duyuru,sikayet,diger];
navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
self.window.rootViewController = self.navigationController;
// [self.window addSubview:self.navigationController.view];
[self.window makeKeyAndVisible];
return YES;
firstTab viewcontroller have button and click events:
-(void)btnClick:(id)sender
{
[self.navigationController pushViewController:haberler animated:NO];
}
when I click UIViewController it is opening, but not showing UITabBarController. How can I solve this problem?
You have UITabBarController as rootViewController of your UINavigationController. And UINavigationController as root Controller of your app. Instead of that you have to set UITabBarController as root Controller of your App and add UINavigationController in each tab.
Check this answer.
You should try using my following snippet
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:#"anasayfaViewController" bundle:nil];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstTab];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:#"SehirRehberiViewController" bundle:nil];
UINavigationController *secondNav = [[UINavigationController alloc] initWithRootViewController:sehirRehberi];
// object for tabbarviewcontroller
self.tab.viewControllers = [NSArray arrayWithObjects:firstNav,secondNav,nil];
I've shown you the sample for two tabs inside tabbarcontroller. You can customise it as per your need.
Enjoy Programming!
First thing is that you need to create Array of Your All view-controller(Navigation Controller) like
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController2,navigationController1,navigationController3,nil];
and
you need to set Winodw's Rootviewcontroller is
[self.window setRootViewController:tabBarController]; not a Navigationcontroller
As par you Code example:-
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:#"anasayfaViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:#"SehirRehberiViewController" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:sehirRehberi];
duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:#"duyuruViewController" bundle:nil];
UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:duyuru];
sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:#"sikayetViewController" bundle:nil];
UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:sikayet];
digerViewController *diger = [[digerViewController alloc] initWithNibName:#"digerViewController" bundle:nil];
UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:diger];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navigationController1,navigationController2,navigationController3,navigationController4,navigationController5];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
return YES;
UPDATE:-
If you want to TabbarController adding at button Click for NextViewcontroller then you can do with something different way like Bellow :-
For example you have loginScreen while app lonch and it login button click you need to push a view-controller and that View-controller contain those Tabbar.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
LoginViewcontroller *objLogin = [[LoginViewcontroller alloc] initWithNibName:#"LoginViewcontroller" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
In loginViewcontroller LoginButton action:-
-(IBAction)LoginSuccess
{
anasayfaViewController * firstTab= [[anasayfaViewController alloc] initWithNibName:#"anasayfaViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:firstTab];
SehirRehberiViewController *sehirRehberi = [[SehirRehberiViewController alloc] initWithNibName:#"SehirRehberiViewController" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:sehirRehberi];
duyuruViewController *duyuru = [[duyuruViewController alloc] initWithNibName:#"duyuruViewController" bundle:nil];
UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:duyuru];
sikayetViewController *sikayet = [[sikayetViewController alloc] initWithNibName:#"sikayetViewController" bundle:nil];
UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:sikayet];
digerViewController *diger = [[digerViewController alloc] initWithNibName:#"digerViewController" bundle:nil];
UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:diger];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[navigationController1,navigationController2,navigationController3,navigationController4,navigationController5];
[self.navigationController pushViewController:self.tabBarController animated:YES];
}
What is the way to use multiple buttons on root view controller linked with different tab views in Xcode 4.5?
I have got 4 buttons on the home screen, I want the flow goes as when I tap on a button1 it should go to tab1 similarly when I tap on button2 tab2 should be open.
What should I do?
Dummy Code Ignore this.
{
tabBarController.viewControllers = controllers;
window.rootViewController = tabBarController;
}
you can do it like bellow..
First Create object of UITabBarController in AppDelegate class and alloc in applicationDidFinishLaunching: method like bellow..
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController2 = [[[UITabBarController alloc]init]autorelease];
self.tabBarController3 = [[[UITabBarController alloc]init]autorelease];
After create method for set Different Tab as a RootViewController like bellow...
-(void)setRootViewControllerTab1{
UIViewController *viewController1, *viewController2;
UINavigationController *navviewController1 , *navviewController2,;
viewController1 = [[[HomeViewController alloc] initWithNibName:#"viewController1" bundle:nil] autorelease];
navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navviewController1.title = #"Title1";
viewController2 = [[[HowItWorksViewController alloc] initWithNibName:#"viewController2" bundle:nil] autorelease];
navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
navviewController2.title = #"Title2";
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
-(void)setRootViewControllerTab2{
UIViewController *viewController3, *viewController4;
UINavigationController *navviewController3 , *navviewController4;
/////TAB 2/////***********
viewController3 = [[[CUHomeViewController alloc] initWithNibName:#"viewController3" bundle:nil] autorelease];
navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
navviewController3.title = #"Title3";
viewController4 = [[[CUFavouritiesViewController alloc] initWithNibName:#"viewController4" bundle:nil] autorelease];
navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
navviewController4.title = #"Title4";
self.tabBarController2.viewControllers = [NSArray arrayWithObjects:navviewController3, navviewController4, nil];
self.window.rootViewController = self.tabBarController2;
[self.window makeKeyAndVisible];
}
Call above method with AppDelegate object like bellow...
For Example: button1 clicked at that time in method write this code...
- (IBAction)btn1_Clicked:(id)sender{
AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[objApp setRootViewControllerTab1];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController4 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease]; self.tabBarController.viewControllers = #[viewController1, viewController2,viewController3,viewController4];
self.window.rootViewController = self.tabBarController;
}
Create a tabbar controller like this
Call above method with AppDelegate object like bellow...
For Example: button1 clicked at that time in method write this code...
- (IBAction)btn1_Clicked:(id)sender{
AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
objApp.tabbarcontroller.selectedindex = 2;
}
you can change selectedIndex
Just create 4 viewControllers and append below code in app delegates method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController4 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[viewController1, viewController2,viewController3,viewController4];
self.window.rootViewController = self.tabBarController;
I have a problem in my appdelegate. I want to add a navigation bar, but it doesn't work.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.tabBarController = [[UITabBarController alloc] init];
UniversViewController *universViewController = [[UniversViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
universViewController.title = #"univers";
CategoriesViewController *categoriesViewController = [[CategoriesViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:categoriesViewController];
navigationController.title = #"categories";
[navigationController setNavigationBarHidden:NO];
ProduitsListinTableViewController *produitListe = [[ProduitsListinTableViewController alloc] initWithNibName:#"ProduitsListinTableViewController" bundle:nil];
produitListe.title = #"troisième";
_tabBarController.viewControllers = [NSArray arrayWithObjects:universViewController, categoriesViewController, produitListe, nil];
[self.window setRootViewController:_tabBarController];
[self.window makeKeyAndVisible];
return YES;
}
Do I have to add something in UniversViewController, CategoriesViewController and ProduitsListinTableViewController or this is directly in the appdelegate?
Try this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2,*viewController3,*viewController4,*viewController5;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
viewController1 = [[[HomeViewController alloc] initWithNibName:#"HomeViewController" bundle:nil] autorelease];
navController=[[UINavigationController alloc] initWithRootViewController:viewController1];
viewController2 = [[[SearchViewController alloc] initWithNibName:#"SearchViewController" bundle:nil] autorelease];
navController2=[[UINavigationController alloc] initWithRootViewController:viewController2];
viewController3 = [[[LocationsViewController alloc] initWithNibName:#"LocationsViewController" bundle:nil] autorelease];
navController3=[[UINavigationController alloc] initWithRootViewController:viewController3];
viewController4 = [[[CallViewController alloc] initWithNibName:#"CallViewController" bundle:nil] autorelease];
navController4=[[UINavigationController alloc] initWithRootViewController:viewController4];
viewController5 = [[[MyBookingsViewController alloc] initWithNibName:#"MyBookingsViewController" bundle:nil] autorelease];
navController5=[[UINavigationController alloc] initWithRootViewController:viewController5];
}
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController2,navController3,navController4,navController5,nil];
//self.window.rootViewController =self.navController;
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I always follow this approach when I have both a UINavigationController and a UITabbarController:
You need to start with a view based application. And then create a UITabbarController in your appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthesize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
I always follow this approach and it never fails. The tabs are always visible. You can make changes according to your code.
According to Apple, I can combine UINavigationController and UITabBarController using the code, e.g.
MyViewController1* vc1 = [[MyViewController1 alloc] init];
MyViewController2* vc2 = [[MyViewController2 alloc] init];
MyViewController3* vc3 = [[MyViewController3 alloc] init];
MyNavRootViewController* vc4 = [[MyNavRootViewController alloc] init];
UINavigationController* navController = [[UINavigationController alloc]
initWithRootViewController:vc4];
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, navController, nil];
tabBarController.viewControllers = controllers;
In this setup, only vc4 has the UINavigationController, but what if I want vc1-vc3 also has the UINavigationController?, should I do like..
MyViewController1* vc1 = [[MyViewController1 alloc] init];
UINavigationController* nv1 = [[UINavigationController alloc]
initWithRootViewController:vc1];
MyViewController1* vc2 = [[MyViewController2 alloc] init];
UINavigationController* nv2= [[UINavigationController alloc]
initWithRootViewController:vc2];
MyViewController1* vc3 = [[MyViewController3 alloc] init];
UINavigationController* nv3 = [[UINavigationController alloc]
initWithRootViewController:vc3];
NSArray* controllers = [NSArray arrayWithObjects:nv1, nv2, nv3, nil];
tabBarController.viewControllers = controllers;
Is this the right approach?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [self initializeTabBarItems];
self.navigationController = [[UINavigationController alloc]init];
[self.navigationController setNavigationBarHidden:YES];
self.window.rootViewController = self.navigationController;
[self.navigationController pushViewController:_tabBarController animated:YES];
[self.window makeKeyAndVisible];
return YES;
}
- (NSArray *)initializeTabBarItems
{
NSArray * retval;
/* Initialize view controllers */
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil]autorelease];
UIViewController *viewController4 = [[[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil] autorelease];
UIViewController *viewController5 = [[[FivfthViewController alloc] initWithNibName:#"FivfthViewController" bundle:nil] autorelease];
/* Initialize navigation controllers */
UINavigationController * navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UINavigationController * navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController * navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];
UINavigationController * navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];
UINavigationController * navigationController5 = [[UINavigationController alloc] initWithRootViewController:viewController5];
/* Release View Controllers */
[viewController1 release];
[viewController2 release];
[viewController3 release];
[viewController4 release];
[viewController5 release];
/* Stuff Navigation Controllers into return value */
retval = [NSArray arrayWithObjects:viewController1,viewController2,viewController3,viewController4,viewController5,nil];
/* Release Navigation Controllers */
[navigationController1 release];
[navigationController2 release];
[navigationController3 release];
[navigationController4 release];
[navigationController5 release];
return (retval);
}
You Can Try This ....
Yes Howard, your approach is fine. Apple says this too. I also follow same approach while working with UITabbarController with UINavigationController and it works great for me.
You should have one UINavigationController per tab of your TabBarController. So your 2nd approach is correct. I don't think that you can reuse the same navigation controller for all the tabs.
Yes your approach is correct.
If u have to navigate views into tab then that tab should have navigation Controller.
UINavigationController * navigationCtrl = [[UINavigationController alloc] initWithRootViewController:firstTabViewCtrl];
[arrTabs addObject:navigationCtrl];
Either wise there is no need of navigation Controller inside tab.
[arrTabs addObject:firstTabViewCtrl];
I want to show modal view in the start of the app but it doesn't appear. This is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self initDataBase];
CustomerModel *customer = [[[CustomerPersistor alloc] init] getLoggedCustomer];
self.window.rootViewController = self.tabBarController;
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *profileViewController = [[[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil] autorelease];
profileViewController.title = #"Profile";
UINavigationController *profileNavigation = [[[UINavigationController alloc] initWithRootViewController:profileViewController] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:profileNavigation, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
if(customer == nil) { NSLog(#"HO");
ViewController *login = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
//login.delegate = self.tabBarController.view;
[self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] animated:YES];
}
return YES;
}
How can I fix it?
First, there doesn't appear to be a self.viewController property that is set, and you're instantiating the same "ViewController" twice. This is all wrong:
ViewController *login = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
//login.delegate = self.tabBarController.view;
[self.viewController presentModalViewController:[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] animated:YES];
Try moving this code to your viewDidLoad of your profileViewController...i.e. let the TabBarController load along with its first tab's view controller.
Initiate an instanse from the model view like this:
modelView = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
Please follow the list below:
Set the viewController model presented style
[modelView setModalPresentationStyle:UIModalPresentationPageSheet];
Then present it using:
[self.viewController presentModalViewController:floorView animated:YES];
Then, set the size and location of the model controller like this:
modelView.view.superview.bounds = CGRectMake(0, 0, 700, 550);//it's important to do this after presentModalViewController
modelView.view.superview.center = self.view.superview.center;//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc.
Hope this help you.