switch views using a button, going to a table view, iphone - iphone

My program has 4 buttons and each button calls a different table view. That works fine, but my problem is, the view controller I'm using brings up a table view that covers up my navigation bar and my tab bar. I need to replace that coding with something that will bring up a table and not cover up my nav and tab bars. Here is the coding I'm using:
-(IBAction)buttonNorthWest {
NorthWestViewController *nwController = [[NorthWestViewController alloc] initWithNibName:#"NorthWestView" bundle:nil];
self.nwViewController = nwController;
[self.view insertSubview:nwViewController.view atIndex:0];
[self presentModalViewController:nwViewController animated:YES];
[nwController release];
}
The [self presentModalViewController....] is the problem. Does anyone know how I can replace that code with something that keeps my nav and tab bars?
Thanks,
Jaime

On the iPhone, all modal view controllers must be full screen as seen here http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle
As an alternative you could display the tableview as a subview and adjust the frame so that it does not overlap the nav or toolbar.

Related

Having more than 1 navigation controller in an app

I've been requested to mock up an app with the following design.
The large gray box is the main view area. (UIView)
The 2 pink squares are buttons. They are almost like tabs of a tabbar in how they should function.
What I am struggling to achieve is to get 2 UINavigationbars/Controllers to appear in the UIView(large gray box) when a button is pressed. Not at the same time of course, but which ever Navbar/Controller/View that is shown is dependent on what button was selected.
I can make a UIViewControllers view appear there ok by doing the following
TabViewOne * vcTab = [[TabViewOne alloc] initWithNibName:#"TabViewOne" bundle:[NSBundle mainBundle]];
[self.mainView addSubview:vcTab.view];
That makes the view of TabViewOne appear in my mainView area (gray box).
What I would actually like to happen is that I can get my view to appear here but with a navbar and all the functionality that it brings. I will eventually just hide the nav bar but use its functionality to move up and down the view stack.
This is what I tried to get it working but the view stays blank when I try this :
TabViewOne * vcTab = [[TabViewOne alloc] initWithNibName:#"TabViewOne" bundle:[NSBundle mainBundle]];
UINavigationController * navVC = [[UINavigationController alloc] initWithRootViewController:vcTab];
[[navVC navigationBar] setHidden:YES];
[self.mainView addSubview:navVC.view];
Could somebody please advise me how to do this properly?
Many Thanks,
-Code
You can achieve your requirement from a small trick. You can implement a tab bar controller there. In tab bar controllers each tab can be run inside a separate navigation controller. In the root view controller of both the tab items you have to have that 2 button design. If you use a generic view and add it as a subview you can easily reuse it. Next thing is it will appear the tab bar at the bottom of the view as you have a tab bar controller there. You can hide it simply by making its frame rectangle to a non visible position. After that your tab selection should be done manually based on the users button click.

Why do positions of my UI elements change on popViewController?

I recently started using interface builder, the problem i'm facing right now is when i use the back button of navigation controller, my UI elements' y axis go up by roughly 20-30 px, is there some setting i've to use to avoid this problem ? And they go up only when i use pushViewController, when i use popViewController it loads the way i need.
Code i'm using for pushing:
examVC=[[ExampleClass alloc] initWithNibName:#"ExampleClass" bundle:nil];
[[self navigationController] pushViewController:examVC animated:YES];
I'm attaching the images with the question. Please note how label has gone down about 20-30 px.
Why does this happen? What am i doing wrong ?
Thanks for all the help.
Edit : changed the screens for better clarity
I'm using pushing code on the round rect button.
Screen 1:UI elements set in my IB
Screen 2: How it looks when pushed from previous view
Screen 3: How it looks when popped from the "Next View"
My home view controller had the navigation bar hidden, the screen i posted was the second view which comes after the home view. I wanted to hide navigation bar in the first view only, so i had used :
- (void)viewDidDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewDidDisappear:animated];
}
It caused the problem because i was showing the navigation bar again in viewDidDisappear, so the view would load first then the navigation bar would be shown causing it to overlap.
So i put the same code in viewWillDisappear, which removed the issue. As navigation bar did load before loading of the next view. Now the view loads just like i designed it in interface builder.
Hey I don't know whether it will work for you or not but in your IB change top bar None to Navigation Bar
Then adjust your element accordingly and tun the code.
I tried all of the suggestions here and none of them worked. My UI elements were always lower when popping back to my original view controller. The only thing that fixed this for me was going into my nib file in Interface Builder and turning off Auto Layout.

Navigation Bar + presentModalViewController

I have a navigation bar based application, and at one specific point in the app I have a button on the nav bar that should present a new view using a flip transition (essentially taking a user from a tableview to a map view). I'm currently using
DetailLocationView *detailLocationView = [DetailLocationView alloc] init];
detailLocationView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.view presentModalViewController:detailLocationView animated:YES];
[detailLocationView release];
This code takes the entire view the user is in (navigation bar and table view) and flips it into just the detailLocationView. However, I would like for the detailLocationView to still have a navigation bar. I'm wondering what the best way to have the detailLocationView be loaded in so that it has a flip transition and is still has a navigation bar.
Thanks
pushViewController instead of presentModalViewController will retain the navbar, but will not as you want.
If you want to "flip" and still have the Navbar - you'd have to flip to a new view with the navbar. This is sort of illogical though, from a UI perspective - i.e. when you visually see the view flip - you're seeing it change to something completely different - so for the view to flip and then reveal the same navbar may be a bit confusing.

Full screen UIImage view

I have an application with a navigation bar and a tab bar. A user can navigate to a view which displays images in a scroll view. I'd like to have the same behavior as the iPhone photo app: Nav bar at the top, tool bar at the bottom, which will hide or show based upon a tap.
I'm moving my view to the window object in order to achieve full screen mode. This works fine:
myView = [self.view retain];
self.view = nil;
[window addSubview:myView];
But when I want to redisplay the Nav & tool bar, I run into a problem. The bars show fine, but the view is empty, and I can't seem to add any content to the view:
[myView removeFromSuperview];
self.view = myView;
I got a lot of good info from this post
but can't quite get the right combination.
By simply setting the controller's view, you aren't adding it as a subview to anything else, so it will never appear.
Moving views around like this can get a little tricky. I recommend that you not move the view from one to the other, but instead have two UIViews. Add second UIView to the window's subview and set it to hidden=YES initially. When you want to show it, set the image for the UIImageView, and then set the hidden property to NO.
what's wrong with just using setNavigationBarHidden: animated: and setToolbarHidden:animated:?

Presenting modal view occasionally hides the navigation bar

I've come across this twice now.
Sometimes using the following line of code:
[self.navigationController presentModalViewController:aViewController animated:YES];
displays the view, but the navigation bar is then hidden.
I can write:
[self.navigationController setNavigationBarHidden:NO];
to my hearts content, everywhere I can think of with no effect.
Has anyone ran into this?
Am I doing something silly?
No, I ran into this as well. The problem is that when you present a modal view controller with a UIViewController based class, it does not extend the calling navigation controller's nav bar onto the modal. The modal view covers the entire screen. What I ended up doing to solve the problem was to create a UINavigationController and push the UIViewController based class onto it, and then do presentModalViewController to the navigation controller's instance.
like:
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController:cntrol animated:YES];
[cntrol release];
That allowed me to have a nav bar at the top.
I am not sure if that will help in your particular case, the only other thing I would suggest is to replicate the behavior of the modal with a UIAnimation that stops 44px below the top of the phone. That would keep the original navigation bar visible.
#HeatMiser shows a great way to get around the "bug" surrounding the inability to display items on the nav bar. I'm not sure, however, if this is strictly a bug in Presentation, since modal operations ought to trump the underlying view's interface theme. Having the modal operation's theme mimic the underlying UI theme is fine, but wrapping the true modal view with a navigation view feels wrong to me (extra view object just to get a little more behavior).
Instead, the following worked for me and gives the same behavior as "New Message" does in the Mail program (on the iPhone).
In IB, place a UIToolBar at the top of the modal screen (mimicking the navigation bar) with "Cancel" and "Save" UIBarButtonItem's and a Flexible Space Bar Button Item in between to get the buttons to align left and right. Then, add a UILabel centered over the UIToolBar (The Font Helvetica, Bold, Size 18 appears to match the Navigation Bar Title). Connect the buttons to IBAction's on the modal's UIViewController, and you're done.
If there is a navigation controller active, then you should just use
[self.navigationController pushViewControllerAnimated:how];
to slide another view controller in, while giving yourself and the user into a consistent user interface complete with 'automatic' back button support.
Once a navigation controller is in use, presenting a modal view controller should only be done to enlarge the usable area on the screen. And then, you should really use a fancy animation to let the user know that you are stepping away from the "task" or "steps" that the navigation controller was embodying.
Maybe this is obvious, but once you're done with the modal view and want to dismiss it, you should do something like this in your modal vc:
[parentController dismissModalViewControllerAnimated:YES];
Where parentController is a reference to the vc from where you are presenting the modal view.