add overlay view over all other views - iphone

how do you add an overlay view that goes over everything. eg over a tab bar controller, and a navigation controller?
thanks

Find the "top" view in your stack, and add a subview. eg
[self.tabBarController.view addSubview:myView];
The hardest part is finding the topmost view; with a tab bar, it will be its own view.

Add a window. That's what the popup keyboard and UIAlertView do, you can see that in this view dump.

Use a modal view controller. Have a read of this guide:
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
Presenting the view controller itself is easy:
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];

Related

How to use a Button in Container View's Navigation Controller to go back to last view

Hi I am a newbie in iOS
In my project I didn't want to use a Navigation Bar because of the tint effect, so I used a container view to create something similar except for the back button I used an image with a button on the back.
I have used a Container View(connected to a Navigation Controller) to include a label and a button with an image on top of that button. I want the view to go back to the previous view when I click the button (the one inside the container view's navigation controller). I tried the usual [self.navigationController popViewControllerAnimated:YES]; but with no result. How do I execute this task?
If you are using
[self presentViewController:yourVC animated:YES completion:nil];
to present your View Controller, then you should use
[self dismissViewControllerAnimated:YES completion:nil];
to dismiss your present View Controller and to go back to the last View Controller.
the view which you want to push to connect with UINavigation Controller pls clear that you is your app navigation based app, if not pls add it in App Delegate
ViewController *ViewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:ViewController] autorelease];

iOS UINavigationController

I am having an issue when im using navigation controller.
My program is laid out where I have a start screen (not in the navigation controller) and then when you press a button it sends you to the navigationController and new view.
Is there a way to get back out of the navigation controller back to that home screen using a back button.
OR
if i included the start screen as the root for the navigation controller is there a way to hide the top bar in the view.
The reason i didn't include the start screen originally is because I didn't want the navigation bar on the screen.
Thanks.
For hide the UINavigationBar then use bellow line in viewWillAppear: method of your start screen viewController..
[self.navigationController setNavigationBarHidden:YES];
OR
[self.navigationController setNavigationBarHidden:YES animated:YES];
AND you can go back to previous view and also home screen or parent view with bellow code...
-(IBAction)yourButton_Clicked:(id)sender{
[self.navigationController popViewControllerAnimated:YES];//// For back to Previous view
// [self.navigationController popToRootViewControllerAnimated:YES]; // For Back to home screen or parent view
}
Well there is a very simple method to just hide the UINavigationBar when you want to like this in the ant view :-
[self.navigationController setNavigationBarHidden:YES];
and the in the view in which you would want to show it simply unhide it like this :-
[self.navigationController setNavigationBarHidden:NO];
You can use navigation bar in all screens. But for the screen where you dont want to show it, Just use hide property for navigation bar. That screen will not show navigation bar on top.
[[self navigationController] setNavigationBarHidden:YES animated:YES];
It'll resolve your issue.
- (void) viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void) viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
By implementing this on your home Screen you can hide the top bar
If you're using storyboard you could create a UIButton and link the view back modally.
Also check out https://stackoverflow.com/a/8348527/401787 for navigating between view controllers.
Actually your requirement are not clearer.
But to hide your navigation controller you can use,
self.navigationController.navigationBarHidden=YES;
and also you can add your custom button on to the navigation bar.
UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithTitle:#"Back" style:UIBarButtonSystemItemAction target:self action:#selector(backBtnClicked:)];
self.navigationItem.leftBarButtonItem=leftBtn;
and you can right your requirements in the backBtnClicked: method.
you can also navigate to your root level view controller.
U can hide the navigation bar using
self.navigationController.navigationBarHidden = YES;
Add the start screen as sub view to navigation's root view controller.
[self.view addSubview:startScreen.view]
Later Remove it by [startScreen.view removFromSuperview] and set the navigationBarHidden flag to NO.

iPhone - change navigation controller's view, using a button in a subview

I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.
However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.
At the moment, it builds and runs, but the new view is not pushed. Any ideas?
Click method on on the ScrollItem button:
MyViewController *newView = [[MyViewController alloc] initWithNibName:#"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
... i guess it is because, self doesn't have a navigation controller, but the rootview does.
Thanks!!
The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.
Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.
So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

tabBarController navigation problem/question

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}
A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.

Using a UINavigationViewController on its own

In my application which is based on a tabbar view controller with many uinavigationviewcontrollers for each tabbar items, I want to present at some point (at application launch) with a call to presentModalViewController that contains a uinavigationcontroller as a root so the user can do a few things... when he or she is finished, the Done button at the top right corner can be tapped to dismiss the modal view controller and then return to the base tabbar view.... How can I do that with Interface Builder ?
In XCode, create a new View XIB file and open it in Interface Builder. In this xib file, delete the View and drag a UINavigationController into it's place.
Then, in your view controller code, something like
UINavigationController *controller = [[UINavigationController alloc] initWithNibName:#"ModalViewController" bundle:nil];
[self presentModalViewController:controller animated:YES];
[controller release];
Will load your XIB and present it.
Hope this helps, any other questions don't hesitate to comment on this answer!
S