I created in code UINavigationController, but I want to change style to black translucent
FirstViewController *fvc = [[FirstViewControlelr alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] init];
navcon.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[navcon pushViewController:fvc animated:NO];
[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];
return YES;
But he doesn't change. Help me please!
I suspect it has something to do with the fact that you're accessing a navigation controller's navigation controller. Your navigation controller doesn't live in another navigation controller, so you're setting the bar style of something that isn't there.
You want this:
navcon.navigationBar.barStyle = UIBarStyleBlackTranslucent;
Also you can make a navigation controller and immediately initialize it with a root view controller so you don't have to push it in manually, like this:
FirstViewController *fvc = [[FirstViewController alloc] init];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:fvc];
[fvc release];
navcon.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self.window addSubview:navcon.view];
[self.window makeKeyAndVisible];
return YES;
And yes, you forgot to release fvc in your own code.
Related
Please, help to understand the navigation. I'm working with xibs. The scheme is: https://www.dropbox.com/s/o82fxpte0hmyxcq/Scheme_Simple.jpg .
Here's my code :
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
FirstViewController *firstViewController = [[firstViewController alloc] initWithNibName:#"firstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
#implementation FirstViewController
- (IBAction)button1Tapped:(id)sender {
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.title = #"View2";
[self.navigationController pushViewController:secondViewController animated:YES];
}
#implementation SecondViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
thirdViewController.title = #"View3";
if (indexPath.row == 0) {
[self.navigationController pushViewController:thirdViewController animated:YES];
[secondViewTableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
So, I have questions:
Where should I create the next view? In my code view has created in "previous" class: view2 created in FirstViewController, view3 created in SecondViewController etc. All new ViewControllers are inside the method that initiates the navigation, is it right way? I think it's wrong, but the navigation is working.
Problems with headers in the navigation bar. It turns out that the title of view2 is only displayed when moving from view1 to view2, but when going back from view3 to view2 – header disappears. I googled, tried to add self.title = #"name" to viewDidLoad, initWithNibName, viewWillAppear – none of this works.
So I've solved the problem with disappearing title of navigation bar. The problem was in my custom back button: self.navigationItem.title = #"";
It was working and title "Back" from my back button disappeared but also title of navigation bar disappeared too. The right way to make back button untitled is:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
Not sure how to title this question, but i'v got such a problem: Up until now i my app runs mainly in one navigationcontroller with table views. But now i'm trying to integrate dropdown settings menu, and can't get it properly done.
The way i'v done now and it works
The changeController is called from one button. ChangeController is in appdelegate.
- (void) ChangeController
{
self.window.backgroundColor = [UIColor blackColor];
DropDownExample *e = [[DropDownExample alloc] initWithStyle:UITableViewStyleGrouped];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:e];
[e release];
[self.window addSubview:self.navigationController.view];
self.window.backgroundColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
}
But this approach has consequances - there is no transition if button is pressed, the settings menu appears instantly, you cannot go back via navigation bar above (nothing there).
So how to do this properly?? I'm new to ios, so just tell me the whole idea how to do this.
Didfinishlaunchingwithoptions method from appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease
];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
TableViewController *tableVC = [[TableViewController alloc] initWithNibName:#"TableView" bundle:nil andType:CONTROLLER_TYPE_FIRST];
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:tableVC];
self.navigationController = navC;
[tableVC release];
[navC release];
self.window.rootViewController = _navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Ok, here's the answer. Write the method changeController in the same class where the Button exists which calls changeController
In the method, write this.
- (void) ChangeController
{
DropDownExample *e = [[DropDownExample alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:e animated:YES];
[e release];
}
What you want is to insert new UIViewController on the top of the present Stack. If you would be having a navigation Bar at the top by default then there would be a back Btn by default, which would pop up that controller.
I have this buttons controller with buttons xib. This buttons is included in my other views. The problem I have is button clicked navigation.
-(IBAction) gotoReport:(id) sender
{ NSLog(#"ll");
ReportStepOne *report = [[ReportStepOne alloc]init];
[self.navigationController pushViewController:report animated:YES];
[report release];
}
I could see the log message, but navigation doesn't work. I guess I should not use self?
appDelegate.H
UINavigationController *navCon;
appDelegate.M
navCon = [[UINavigationController alloc] init];
[navCon setNavigationBarHidden:YES];
Login *login = [[Login alloc] init];
[navCon pushViewController:login animated:NO];
[login release];
[window addSubview:navCon.view];
[self.window makeKeyAndVisible];
Your first example of IBAction is correct, it should pus the view. If it's not pushing, you need to check your XIB to make sure you have connected the correct button to this IBAction.
in your app delegate, do this instead:
Login *login = [[Login alloc] init];
// Make navController a property..
self.navController = [[UINavigationController alloc] initWithRootViewController:login];
//This is the key..
[[self window] setRootViewController:self.navController];
[self.navController setNavigationBarHidden:YES];
[login release];
[self.window makeKeyAndVisible];
I have in my app class UINavigationController (with NIB) and I want to open this as a ModalView.
I do that so: (ColorInfo is just this UINavigationController class)
ColorInfo *InfoScreen = [[ColorInfo alloc] initWithNibName:#"ColorInfo" bundle:[NSBundle mainBundle]];
[InfoScreen setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:InfoScreen animated:YES];
It displays me an empty UINavigtionController element. Tell me please how could I open ColorInfo (as UINavigationController) in ModalView, where I will be able to navigate through?
I thought I can complete ColorInfo with all pushViewController methods and then open it over another screen in ModalView.
Tell me how to reach this effect.
From what you've stated you've inherited UINavigationController in ColorInfo which is not what you want. You want ColorInfo to be the root view of a UINavigationController like so
ColorInfo *InfoScreen = [[ColorInfo alloc] initWithNibName:#"ColorInfo" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:InfoScreen];
[self presentModalViewController:nav animated:YES];
I recommend you read the navigation controller documentation for further clarity.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Use this with InfoScreen controller and DON'T subclass UINavigationController ...
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:InfoScreen];
[navController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:InfoScreen animated:YES];
I try to change the modalTransitionStyle property of my modal view. Every style work except for FlipHorizontal. If I choose this, nothing happens.
I have an UINavigationController which should be flipped in.
Heres the code:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
loginNavCon.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];
Thanks for your help.
Ok, I figured it out!
The point is to set it in the pushing UIViewController, not in the pushed one.
So in my example code it has to look like this:
UINavigationController *loginNavCon = [[UINavigationController alloc] init];
loginNavCon.navigationBar.barStyle = UIBarStyleBlack;
// push login view
LogInViewController *liVC = [[LogInViewController alloc] initWithStyle:UITableViewStyleGrouped];
[loginNavCon pushViewController:liVC animated:NO];
[liVC release];
// show login view
/** changed **/
self.window.rootViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
/*************/
[self.window.rootViewController presentModalViewController:loginNavCon animated:YES];
[loginNavCon release];