This is my AppDelegate, i set a title "Pizza", but when i build and play the application, the text don't will appear.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[navigationControllerPizza setTitle:#"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:#"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Why?
According to Your Question you can set title of ListaPizzeViewController using object of ListaPizzeViewController like Bellow:-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
[listPizzeVC setTitle:#"Pizza"]; // Here it is you can set Title of Object of Viewcontroller so set like thin not [navigationControllerPizza setTitle:#"Pizza"];
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
[navigationControllerIngradient setTitle:#"Ingredient"];
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
go into your ListaPizzeViewController, inside the viewDidLoad write
self.title = #"Pizze";
self.navigationItem.title=#"pizza";
simply call this.
Try to set title in viewWillAppear method.
of "listPizzeVC" as
self.title=#"Pizza";
IT is title is ViewController property so use view controller object and title set I write the code under.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UITabBarController *tabBarController = [[UITabBarController alloc]init];
ListaPizzeViewController *listPizzeVC = [[ListaPizzeViewController alloc]init];
UINavigationController *navigationControllerPizza = [[UINavigationController alloc]initWithRootViewController:listPizzeVC];
//[navigationControllerPizza setTitle:#"Pizza"];
listPizzeVC.title=#"Pizza";
navigationControllerPizza.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
ListIngredientsViewController *listIngredientVC = [[ListIngredientsViewController alloc]init];
UINavigationController *navigationControllerIngradient = [[UINavigationController alloc]initWithRootViewController:listIngredientVC];
//[navigationControllerIngradient setTitle:#"Ingredient"];
listIngredientVC.title=#"Ingredient";
navigationControllerIngradient.tabBarItem.image = [UIImage imageNamed:#"Default.png"];
[tabBarController setViewControllers:#[navigationControllerPizza, navigationControllerIngradient]];
[self.window setRootViewController:tabBarController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
I hope it is useful too.
Your code should not be in the appDelegate but in a viewcontroller class that inherits from UIViewController and attach this class to your xib or storyboard screen. One viewcontroller per screen. Add your code to the viewDidLoad or create your own methods. When this doesn't work you might wanna try and post your question again. ;).
I recently started iOS development, it helped me to take little steps and create small project that aimed for learning one thing at a time this way you will learn really fast and efficient without too much frustration. Good luck!
Related
I want to make it translucent black, why doesn't this work?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UINavigationController *viewController1 = [[UINavigationController alloc] init];
viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent;
RSSViewController *rssViewController = [[RSSViewController alloc] init];
[viewController1 addChildViewController:rssViewController];
UIViewController *viewController2 = [[CalendarViewController alloc] initWithNibName:#"CalendarViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[self customizeInterface];
return YES;
}
When I put viewController1.navigationBar.barStyle = UIBarStyleBlackTranslucent; navigation items simply disappear...
Use this
viewController1.navigationBar.tintColor = [UIColor blackColor];
viewController1.navigationBar.translucent = YES;
This may be a stupid question but I programmatically added a UINavigationController to my app. If possible, I wanted to just add it to the top of all my windows except for the very first .xib. Maybe even just hide it on my first .xib. Is it possible to even do that? I think of my first .xib file that opens up to the rest of my app like a cover page and I rather that blue bar not show up at the top of that. I wish I could show you pictures but don't have enough reps yet. Thanks!
Below is the code I believe helps me to provide each page of app with the back bar:
#import "McCormick_TaylorViewController.h"
#implementation McCormick_TaylorAppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
// Override point for customization after application launch.
self.viewController = [[[McCormick_TaylorViewController alloc]
initWithNibName:#"McCormick_TaylorViewController" bundle:nil] autorelease];
UINavigationController * navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
in your McCormick_TaylorViewController's viewWillApper: method
just use bellow code...
[self.navigationController setNavigationBarHidden:NO animated:YES];
and in other view controller in navigationbar ot display then in another viewController's viewWillAppear just use bellow code..
[self.navigationController setNavigationBarHidden:NO animated:NO];
Use this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
// Override point for customization after application launch.
self.viewController = [[[McCormick_TaylorViewController alloc]
initWithNibName:#"McCormick_TaylorViewController" bundle:nil] autorelease];
UINavigationController * navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
[navController.navigationBar setHiden:YES]; // hides navigation bar
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
I want to know that how can we setup a UIViewController in a UINavigationController without using UITableView to its Root View Controller. Any help regarding this? Thanks in advance.
You can do that as follows:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ...
UIViewController *myViewController = [[UIViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window.rootViewController = navigationController;
// ...
}
You can replace the class of myViewController and/or initialize it using a nib if you want.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:[[OptionViewController alloc]initWithNibName:#"OptionViewController" bundle:nil]];
self.window.rootViewController=nav;
self.window.backgroundColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
return YES;
}
It's working for me:
set your tabviewcontroller on window, then it will work properly.
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UITabBarController *tabVC = [self.storyboard instantiateViewControllerWithIdentifier:#"MyMainView"];
[window setRootViewController:tabVC];
UINavigationController pushViewController:animated:
I m trying to change the color of navigation bar of UINavigationController by using
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
in the below given code but its not working.
#import "uitextviewAppDelegate.h"
#import "uitextviewViewController.h"
#implementation uitextviewAppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
#synthesize navigationController = _navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[uitextviewViewController alloc] init];
UINavigationController *navigationController=[[UINavigationController alloc] init];
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
[navigationController pushViewController:_viewController animated:YES];
[_window addSubview:navigationController.view];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Can anyone tell why it is not changing the color of the navigation bar of the UINavigation Controller.
Thanks in advance.
Looking at these two lines:
UINavigationController *navigationController=[[UINavigationController alloc] init];
self.navigationController.navigationBar.tintColor = [UIColor brownColor];
What connects the first navigationController with self.navigationController?
Nothing, as far as I can tell.
You need to assign self.navigationController to navigationController.
Something like:
self.navigationController = navigationController;
I have a problem with switching from one viewcontroller to another.
Here is what I have :
In my "AppDelegate_iPad.m" :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
[window addSubview:loginView.view];
[self.window makeKeyAndVisible];
return YES;
}
That works. Now I have a login button on that screen and when pressed it calles this :
- (IBAction)doPressLoginButton
{
DebugLog(#"doPressLoginButton");
MenuViewController_iPad *menuView = [[MenuViewController_iPad alloc] initWithNibName:#"MenuViewController_iPad" bundle:nil];
[self.navigationController pushViewController:menuView animated:YES];
[menuView release];
}
The problem is that nothing happends. I assume I am missing the actual navigationconroller ?!
Hope that anyone can help.
Thank you
You should create a UINavigationController instance variable in your app delegate. Then, make sure you synthesize it and release it in your dealloc method.
Your implementation of application:didFinishLaunchingWithOptions: could look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// window is usually an IBOutlet
CGRect frame = [UIScreen mainScreen].bounds;
window = [[UIWindow alloc] initWithFrame:frame];
window.backgroundColor = [UIColor blackColor];
LoginViewController_iPad *loginView = [[LoginViewController_iPad alloc] initWithNibName:#"LoginViewController_iPad" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginView];
[loginView release];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
Now you'll be able to use self.navigationController.
I assume I am missing the actual navigationconroller ?!
you are right. :D
self.navigationController returns nil if you don't set up an NavigationController.
And any messages send to nil object will be ignored.
If you only need switch from one to another.
using
[self presentModalViewController:modalViewController animated:YES];
instead.