assignment to readonly property - viewcontroller

This has been working just fine fore about 4 hours and i didn't even touch it but now I'm getting an assignment to readonly property and _tabBarController? Did you mean UITabBarController? What i had did was take this from the appdelegate because i added a login screen, at the login screen i haven't coded it so i just made the submit button on the login screen run the tabview part of my application. So I don't know what i did like i said its been working for a long time like that. Anyone have any ideas?
- (IBAction)submit:(id)sender
{
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
UIViewController *viewController3 = [[[AlarmViewController alloc] initWithNibName:#"AlarmViewController" bundle:nil] autorelease];
UIViewController *viewController4 = [[[BusPassViewController alloc] initWithNibName:#"BusPassViewController" bundle:nil]autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = #[viewController1, viewController2, viewController3, viewController4];
[self presentViewController:_tabBarController animated:YES completion:nil];
}

Related

RootViewController to TabBarViewController

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;

navigationcontroller title and button

In my tab based application delegate i added the navigation controller as like the following,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
UIViewController *viewController3 = [[view1 alloc] initWithNibName:#"view1" bundle:nil];
UIViewController *viewController4 = [[view2 alloc] initWithNibName:#"view2" bundle:nil];
UIViewController *viewController5 = [[view3 alloc] initWithNibName:#"view3" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2,viewController3,viewController4,viewController5];
navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];
[self.window addSubview:[navigationController view]];
self.window.rootViewController = self.navigationController;
i would not be able to added the title in each view. While adding it doesn showing the title?Pls help me to resolve this issue
use bellow code...
Here i add UINavigationController to every tab and also assign title for tab and also for UINavigationBar like bellow...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;
UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5;
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[[YourViewController1 alloc] initWithNibName:#"YourViewController1" bundle:nil] autorelease];
navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
navviewController1.title = #"Home";
// navviewController1.navigationBarHidden=YES;
viewController2 = [[[YourViewController2 alloc] initWithNibName:#"YourViewController2" bundle:nil] autorelease];
navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];
// navviewController2.navigationBarHidden=YES;
navviewController2.title = #"HowItsWork";
viewController3 = [[[YourViewController3 alloc] initWithNibName:#"YourViewController3" bundle:nil] autorelease];
navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];
// navviewController3.navigationBarHidden=YES;
navviewController3.title = #"Join Us";
viewController4 = [[[YourViewController4 alloc] initWithNibName:#"YourViewController4" bundle:nil] autorelease];
navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];
// navviewController4.navigationBarHidden=YES;
navviewController4.title = #"Become";
viewController5 = [[[YourViewController5 alloc] initWithNibName:#"YourViewController5" bundle:nil] autorelease];
navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5];
// navviewController4.navigationBarHidden=YES;
navviewController5.title = #"Contact Us";
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil];
self.window.rootViewController = self.tabBarController;
}
[self.window makeKeyAndVisible];
}
2)OR
Also you can simple assign title in your particular class like bellow...
-(void)viewWillAppear:(BOOL)animated{
self.title = #"yourTitle";
}
i hope this helpful to you...
Go to viewdidload method in every tabbar controller & use line:
navigationController.title=#"hello";
In every viewcontroller viewdidload
self.navigationcontroler.title=#"firstVC";
"title" is the property of UIViewController and UINavigationController is the subclass of UIViewController you can also access it object of UINavigationController, just like navviewController.title = #"myTitle"; and for more detail check Apple Docs. Hope it will help. Cheers
You have added TabBar Controller inside a Navigation Controller so you cannot add title and arises this issue.
Try to add each navigation controller with View controller inside tabbar controller.
I mean add ur ViewController as a root View controller of navigation controller then add to tab Bar controller.
viewController1 = [[[YourViewController1 alloc] initWithNibName:#"YourViewController1" bundle:nil] autorelease];
navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];
Now then ad this navigation controller inside to tabbar controller. Do this for all other viewcontrollers

Should I use an individual UINavigationController per Tab Bar

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];

iOS tab bar not show modal view

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.

ZUUIRevealController with UITabBarController instead of UINavigationController

I'm trying to implement the ZUUIRevealController into a project of mine, this app uses a UITabBarController with 3 tabs.
I went through the screencast and sample code multiple times, but I can't figure out why
[self.navigationController.parentViewController respondsToSelector:#selector(revealToggle)]
only responds with false.
In my appdelegate I just create a simple UITabBarController and add is as a rootViewController:
UITableViewController *activityViewController = [[[ActivityViewController alloc] initWithNibName:#"ActivityViewController" bundle:nil] autorelease];
UIViewController *agendaViewController = [[[AgendaViewController alloc] initWithNibName:#"AgendaViewController" bundle:nil] autorelease];
UIViewController *settingsViewController = [[[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil] autorelease];
UINavigationController *activityNavController = [[[UINavigationController alloc] initWithRootViewController:activityViewController] autorelease];
UINavigationController *agendaNavController = [[[UINavigationController alloc] initWithRootViewController:agendaViewController] autorelease];
UINavigationController *settingsNavController = [[[UINavigationController alloc] initWithRootViewController:settingsViewController] autorelease];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:activityNavController, agendaNavController, settingsNavController, nil];
SortViewController *sortViewController = [[SortViewController alloc] init];
ZUUIRevealController *revealController = [[ZUUIRevealController alloc] initWithFrontViewController:self.tabBarController rearViewController:sortViewController];
[sortViewController release];
//self.window.rootViewController = self.tabBarController;
self.window.rootViewController = revealController;
[revealController release];
[self.window makeKeyAndVisible];
But when I do the check in my ActivityViewController, I only get false
if([self.tabBarController.parentViewController respondsToSelector:#selector(revealToggle)])
{
NSLog(#"YAY");
}
else
{
NSLog(#"WRONG");
}
It seems so simple in the screencast, but it looks like I'm missing something.
ZUUIRevealController: https://github.com/pkluz/ZUUIRevealController
just put : in the if statement while you checking for respondsToSelector: like
if([self.tabBarController.parentViewController respondsToSelector:#selector(revealToggle:)])