How to hide back button in the first view on iPhone? - iphone

I add 3 views for an application and they need to switch from 1-2-3.
Now I add a toolBar and a button 'OK' on the bottom of SwitchViewController, so they can share the button to go to next view.
But how to add a 'Back' button so that I can switch from 2-1 or 3-2 and the button shouldn't be seen in the first view?
Are there any other ways to switch views without sharing the same tool bar button?

It sounds like what you're trying to do is use a UINavigationController. If you instantiate a UINavigationController with the initWithRootViewController initializer you can pass it your first UIViewController. Then you just need to tie whatever action you want to a method that calls [myUINavigationController pushViewController:myOtherViewController animated:YES] to get it to slide over to the second view. The UINavigationController will automatically set up the UINavigationBar and back button you are looking for.

Related

Change view controller on press button

I have two View Controllers, I need to have a button in ViewControllerOne that when I press it Show me ViewControllerTwo.
In storyboard I related both views with a "Presenting Segues" - Push modal. And both views have a view controller class.
I'm not sure what you mean by "I related both views with a 'Presenting Segues' - Push modal." Are you using a navigation controller and want a push segue, or do you want to do a modal segue? A "push modal" is a contradiction in terms.
So, let's imagine that you want a modal segue. So, you put a button on the first view, right-click and drag (or control-click and drag) from that button to the second view.
You'll get a pop up asking for type of segue. Select "modal".
And you're done transitioning from 1 to 2. No code necessary.
If you want a button on the second view to take you back to the first view, you do not want a modal segue from the second view back to the first view, but rather you want to dismissViewControllerAnimated. You can do this via a custom segue, or easier, just have a button which calls dismissViewControllerAnimated. Thus, you'd add a button to the second view, and while the editor is in in "assistant" mode (where the associated .h file is showing below the interface builder; see below if you want to know how to show the .h file at the same time as the Interface Builder screen), right-click (or control-click) and drag from the button on the second view down to the second view controller's .h file:
By the way, if you don't see the .h file there, click on the "assistant" editor button and choose "automatic" for the files to be shown down there, and you should be good:
It will then show you a pop up asking you what you want to do. Select IBAction and give your new method a name:
Then go to your code for the view controller, and add the dismissViewControllerAnimated code:
All that code says (and in this example, I just called my IBAction dismissTwo) is:
- (IBAction)dismissTwo:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
If you want to do a push segue, it's even easier. First, if you don't already have a navigation controller, add one by selecting the first view and choose "Embed in" - "Navigation Controller":
When you do this, you'll have a new navigation controller (which you don't really need to do much with) and the first view will have a navigation bar.
Now, right-click (or control-click) on your first view's button and drag over to the second view:
This time, select the "push" segue:
And you'll know that it worked, because your second view will have a navigation controller
You don't need a button to go back, because the navigation controller will automatically have a "Back" button, so you don't need to add your own.
This is how you achieve a push segue.

iPhone App Dev - Loading a view into another view

I have a root view controller with just a simple navigation button that loads a questionview. When I use pushViewController a back button appears. Instead I want a custom button in the top right of the uinavigationcontroller and I want to remove the back button after the page transition.
how can i achieve this..
Take a look at UINavigationItem. You can accomplish both your goals by properly configuring your view controller's navigation item. Use the -setHidesBackButton:animated: to hide the back button, and the -setRightBarButtonItem:animated: to add your custom button on the right side of the navigation bar.

iPhone Dev - Is it possible to remove a button from a UINavigationController's navigationBar?

When I push a view via my app's navigationController, it automatically puts a back button on the left side of the navigationBar. Is there any way I can just remove this? (I want to put my own buttons on the screen that will allow the view to be popped).
From the comments, you can hide the back button for a viewController by using its navigationItem property. (which is the UINavigationItem corresponding to that viewController in the stack of the navigationController. its how you control what shows up on the bar for specific view controllers (see Apple Doc here)).
To answer your question, set the navigationItem's hidesBackButton property to YES. Something like this probably called in your viewControllers viewDidLoad: or similar method.
myViewController.navigationItem.hidesBackButton = YES;
have you try with self.navigationItem.hidesBackButton=YES;?
If I wanted to do it, I'd hide the Navigation bar on push (non animated hide), add a toolbar, and add any custom stuff I want to the toolbar.
on popping the view controller, make sure to unhide the navigation bar. It'll work

Use two TabBarController

I want to use two different TabBarController. Everything is declared in my AppDelegate. Here is the result :
TBC1Tab1 | TBC1Tab2 | TBC1Tab3 and then when I push a button my new TabBarController : TBC2Tab1 | TBC2Tab2
Each Tab is linked to a view. I use a button on my first tab to go to my second TabBarController with my new tabs. My problem is to go back to my first TabBarController : how to do it ?
So to have my "back" button I add my code in my views. Then if I use my back button I can't go back to my first view from my first TabBarController.
Here is what happens : my view inside my second TabBarController (which is linked to my tab) disappear but my TabBarController doesn't disappear so I can't see my first view with my first TabBarController.
Someone know how to do it ? If you don't understand I will add some pictures. thanks
you need to use two methods in your app delegate
one will work by clicking on your button in tab bar and other will work by clicking on back button
make sure your back button should not be navigation controllers back bar button
that must be custom button
if u have any problem in putting your custom button in the place of back button
put it in right part
thats it other wise if u want to come back it wont work because
navigation controller is the child class of tab bar controller
in NSObject
so
if u want to try with custom button i think u know the answer
other wise call again previous method view did load in 2 nd button

Problem in the flow of custom back button when using UIView controller

I am new to iphone development.I have created a button in UIView controller.On clicking the button it navigates to a another UITableView controller .On clicking the row of the table leads to another UIView controller which has also another table in it.On clicking the row of this table leads to another UIWebView.I have created a custom back button placed on the navigation bar of the UIView controllers and UIWebview.On clicking on the back button just leads me to the main page with a button and not to its just previous UIView.
-(IBAction) goemenbutton : (id) sender
{
[self.view removeFromSuperview];
}
The above method is used for all the custom back button.Please help me out to get the correct flow for the back button.Thanks.
You should probably look at using UINavigationController instead of interchanging several views within one UIViewController. The UINavigationController takes care of a lot of things for you, including back buttons with proper titles and nice animations. It also helps you structure your code and gives you more flexibility down the road.
A UIWebview is not a UIViewController and can not be pushed onto the NavigationController. You should probably look at wrapping it into a UIViewController.