I havent tried this, yet. So is a kind of theoretical question.
I have a tabbarcontroller, and in one view, let us call it "stages", i want to have a button that give you a shortcut to the next tab bar item that is a mapview. In the mapview have I lot of annotations pins, that represent the position of several stages.
Resuming, I want a button in the stages view that jump directly to the annotation pin in the mapview in the next tabbar item.
Should I use like normally the [navigationcontroller pushcontroller: animated:] or exist other method to do it? In last case I will use normally push to another mapview.
If you want to directly jump to the other tab (you don't want a new viewcontroller in your navigationController, but want the other tab's VC), you can create a button or whatever that sets the selectedViewController property of your UITabBarController to the viewController in the other tab. (if your tabbarcontroller has constant tabs (they dont get changed)) you can do this by using the UITabBarController's viewControllers array. Something like this should work:
-(IBAction) jumpToMapTab:(id)sender {
myTabBarController.selectedViewController = [[myTabBarController viewControllers] objectAtIndex:indexOfMyMapTab];
}
`
Related
How do I get a reference to the UINavigationController's backBarButtonItem from the UINavigationController at the top of the stack. In some circumstances I want to disable going back until some networking code is complete.
self.parentViewController.navigationItem.backBarButtonItem.target =
self;
self.parentViewController.navigationItem.backBarButtonItem.action =
#sel...;
doesn't work
delegate method
- (BOOL)navigationBar:(UINavigationBar *)navigationBar
shouldPopItem:(UINavigationItem *)item
doesn't work either.
An answer and a recommendation:
The answer: I would recommend you change your MVC model slightly to have a BOOL property in your model that is on or off depending on whether the network activity is done and then use a delegate/protocol adopted by your QuestionsVC that updates the back button setting as that property changes. You would need to add the following in the delegate method in QuestionsVC:
[self.tabBarController.navigationItem setHidesBackButton:YES animated:YES];
I tested it and it works.
The recommendation: It is never recommended to have UITabBarController inside a UINavigationController (only the inverse is recommended). I would adjust accordingly before you get too deep into your project.
Update:
I can understand the need for a mainVC as startup VC with a button to "start" if you will. You are correct that you need a NavController to be able to push/pop VCs and use segues in Storyboard. But that is not the only way to display a sequence of VCs, you can present/dismiss VCs. So in your case:
1- I would delete the first NavController
2- Make the MainVC the starting VC (entry point) by moving the arrow on the left of the NavController to the left of MainVC
3- Disconnect Main VC from TabBar controller (delete that link) because you will not be able to use segues in SB without Nav Controller. You will have to instantiate and present that tab bar Controller.
4- Add a new object file (.m/.h) - a subclass of UITabBarController and change the class of the tabBarController in IB to the name of your subclass. You might have to build/clean or restart xcode if it does not show on the dropdown of the class list in IB.
5- Create an IBAction method in your mainVC and link it to the button in Main VC.
6- In that method (in your Main VC), add the following code:
yourTabBarControllerSubClassName* myTabController= [self.storyboard instantiateViewControllerWithIdentifier:#"theTab"];
[self presentViewController:myTabController animated:YES completion:nil];
7- Make sure that in your SB that you select the tab bar controller and in the identity inspector, put the SB ID as "theTab" and check "use SB ID".
8- if questions VC or status table VC have a sequence of VCs within each, you can embed each VC in a Nav Controller and that would be ok.
With that the case, you might not need to worry about that back button since it won't exist anymore!
Good luck
Hope this helps.
I was wondering if it is possible to have the following:
One TabBarController with two buttons containing a UITableView in each one.
Then, if one of the TableView cells is clicked, I would like to push to a new TabBarController with a different set of 4 buttons containing other table views.
Can anyone point me in the right direction?
The first thing I tried was set up the first TabBarController with the UITableView under each button. But when I added the second TabBarController to be triggered from a clicked tableview cell, what I got was the first Tab which contains the 2 buttons, and on top of that, the second tab containing the 4 buttons.
I would like the second TabBarController to replace and leave behind the first one.
I hope I explained myself well enough, thank you for your time.
You should change your push segue to a modal segue.
To go back you are going to need to implement a return button in your destination viewController:
- (IBAction) dismiss:(id)sender
{
[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
(note that you must do this in code - you cannot draw a segue line to go back)
At the moment you must have a navigation controller involved in your push segue. When you change to a modal segue you can remove the navController, it won't play a part in the navigation.
Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.
I'm doing this:
HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];
HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = #"Title" won't work.
Thanks!
You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.
(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)
One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).
Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.
How do I navigate back to the previous page with a UITableViewController. I tried to show a navigation bar with navigation button at the top of the screen, but the navigation bar will not show. I know that you have to give the previous view a title but when I go to do that it does not show anything. Also, since it is a UITableViewController I am not able to drop a navigation bar and add a button to the main view. All I would like to do is display my lists and have the option to navigate back to the previous list with a single button in the upper left corner.
The problem you having with the NavigationController is that your tableViewController is not in the NavigationController hierarchy. Want you want to do this when adding the tableViewController:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourTableViewController];
Then you can do this to add yourTableViewController:
[self.view addSubview:navigationController.view];
If you don't want the navigationBar to appear on the tableViewController just use:
self.navigationController.navigationBarHidden = YES;
in yourTableViewController viewWillAppear method.
When your going to add the view after the tableView you just use:
[self.navigationController pushViewController:someViewController animated:YES];
It's not enough to give the child view a title. You need to give the child view's navigation item a title before you present it. For example, in the parent view, before you push the the view to the navigation stack, do something like this...
[MyChildView.MyNavigationItem setTitle:#"A cool Title"];
For the navigation you are trying to achieve you should be using a UINavigationController. It already has the functionality you describe with the navigation bar and back button built into it.
To move to the next screen (which can be a UITableViewController) you use pushViewController:animated: and to move to the previous screen you use popViewControllerAnimated: (although the built in back button will do this for you).
I suggest reading the UINavigationController class documentation if you are not already familiar with it.
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.