I have implemented a UITabBarController for iOS. When I click on the third tab, I need to programmatically go to the first tab .. this works fine with
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
But when the tab time is selected and the appropriate view controller appears, I need to first refresh it. I have tried calling didSelectViewController, but that only seems to work when the tab is pressed. I need to call a method after the focus of the view appears.
Related
I'm working with the Xcode view editor and Swift.
I have my main view which contains a tab bar controller with 2 tabs.
On the second tab, I have a #IBoutlet var myLabel: UITextLabel!. Inside viewWillAppear I put some text in this label.
On the first tab, I have a button which launch a third view through a Push segue, and on this new tab, I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too).
When I launch my app, go in my second tab, the text of the UITextLabel is changed.
I still can go to my first tab and navigate between them it works.
But the problem is when I click on my first tab's button, then on Cancel, then goes back to my second tab, my UITextLabel doesn't change. And I can't perform any action on it anymore. It's not nil though but it's like it's still connected to the first UITextLabel before the segue and not this one.
Where am I wrong ?
Several things are wrong.
With tabbed apps, Apple says that the tab bar controller should be the root level navigation method for the app. It should always be present, and the user should always be able to tap another tap to switch to another part of the app.
So the first tab should connect to a navigation controller. When the user pushes the button, you should push a new view controller onto that navigation controller. The tab bar will still be visible and enabled, and the user will still be able to switch to view controller one.
Next thing:
You say "I have a Back button which gets me back to the main view containing a tab bar controller (through a push segue too)."
That's very wrong. Back buttons should pop a view off of the current navigation stack. They should not be pushing anything. Any time you use a push segue, you are creating and pushing a brand new instance of a view controller, and leaving the other view controllers in the navigation stack.
I have an app that has a toolbar, but I don't want the bar at the top, in order to free more viewing space. Therefore I have decided not to use a navigation controller. I'd like to add a back button to the toolbar. How would I go about this?
Adding the button is easy enough, and setting the action to performSegueWithIdentifier is all fine, but what happens is that the previous view just gets loaded again, rather than show it as it was, like a true back button. So if I tap on the 10th row on a tableView and go to a new page, when I press the back button it loads the view from the top again, instead of showing it as where I scrolled down to last.
Even though you don't want a UINavigationBar, you do want a UINavigationController in this case, because it manages the 'back stack' exactly the way you want it. Just hide its navigation bar by setting its navigationBarHidden property to true (in the Storyboard or in the viewDidLoad function of the root view controller).
You can then use navigationController.popViewController(true) as normal, in response to the user clicking your custom back button.
A little background that I think will help in this question:
I am working on an iOS7 app which basically presents various quotes and allows the user to share these quotes through facebook or twitter. I am implementing this through a tab bar (not a tab bar controller) that I placed at the bottom of the first view controller in the screenshot.
The tab bar's delegate (file owner) is set to be the view controller that it's in. In there I edited the tabbar: didSelectItem: method to handle every button press accordingly. (The first two button presses are just modal segues to twitter and facebook tools.)
Now my question:
Now I am trying to get the third item in the tab bar to cause a segue to the third view controller (upper right). Can I make a tab bar item perform a push segue? How would I go about doing that?
I have been trying to look for a way to do this but seemed to be stumped. I was thinking that maybe this can be done with a tab bar view controller but then I wasn't sure how I could have my original first two tab bar items perform modal segues
Any help would be appreciated
UPDATE:
The two view controllers at the bottom are segued into when the user touches either of the two views in the first view controller (can be ignored for this queston). The third VC (in the top right) I want to be pushed when the user touches the third tab bar item. The bottom two views just display info about quote presented... the top right vc allows the user to enter a new quote and save it.
You only need to connect a segue from the controller with the tab bar to the third controller, and call it manually in the didSelectItem method,
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ([item.title isEqualToString:#"Third"]) { // or whatever your title is
[self performSegueWithIdentifier:#"GoToThird" sender:self];
}
I am creating an app that uses a UITabController with 5 tabs for navigation. Right now my app loads the first tab as the initial view upon app loading.
I want to be able to change that so I have a view that doesn't use my UITabController as the initial view, and once they click the one button on it, it brings them to the First View and displays the TabController.
I thought I'd simply set up a new view, change that one to the initial view controller and have a segue from the button to the TabController, but when I tried that and the view I wanted to with the button loaded first, but when clicking button it said something about needing to set up a NavigationController? Not sure what to do from here.
I think it's best to leave your tab bar controller as the window's root view controller. You can present the initial view controller from the viewDidAppear method of the controller in the first tab, using presentViewController:animated:completion:. Do this with the animated parameter set to NO, and the initial view will be the first thing the user sees. When you're done with that view, just dismiss it, and you'll be back to the first tab's view.
Here is my current problem. I have a UIViewController setup with its data and everything on a small sized view controller. What I am trying to see is if it is possible to connect that to a separate view controller. For example I have a view controller that has a user click a button. Upon pressing the button the UIPicker ViewController would pop up from the bottom and I could go from there. I know how to enable this if the picker is on the same view controller. However, I have no idea how to if its on its own ViewController. Any ideas?
One way to do this would be to put the picker view on the same view controller and make it hidden, and, when they press the button, unhide it or load the other view controller when they press the button; this will display the other view controller, not what's on the current one.