Losing #IBOutlets after Segue - ios

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.

Related

Tabbar controller showing last pushed controller - swift 4

I have tab bar controller with 3 tabs(all view controllers are embedded in navigation controller) while clicking the 3rd tab am showing a view controller with start button, clicking start it goes to the next controller, from this controller by programmatically am pushing to another vc. Now my issue is when I click the 3rd tab it showing the last pushed controller instead of showing a view controller with start button.
If I double click the 3rd tab it showing the current view controller.
Help much appreciated.
That’s how it is supposed to work, if you want to show the root vc for tab 3 you’ll need to call popToRootViewController() on the navigationController.
aVC.navigationController.popToRootViewController()
You would need to call the above when the relevant tab button is tapped, so you can use UITabBarControllerDelegate to find out when that happens.

Changing tabs on Tab Based Application Pushes UI Elements Down

I have a tabbed based iOS application. The fourth tab is linked to a UINavigationController. When I navigate to the home tab from the fourth tab, the UI elements of the home tab are pushed down. However, if I rotate the phone to landscape and then back to portrait, everything has moved up and is in the correct place.
In Storyboard, I set the top bar to none. I have the UINavigationBar hidden in the fourth tab/view controller before I navigate to the home tab.
Why would it be that the rotation fixes the constraints? How can I fix the UI elements such that they are not pushed down in the first place?
Here is a screen shot of my storyboard:
Your question doesn't really make sense. A 4th tab would not be embedded in a navigation controller. Instead, the 4th tab would link to a navigation controller. When you first select that tab you'd see the root view controller and it's navigation bar item. If you pushed a new view controller it would get pushed onto the navigation controller in tab 4. If you switch to one of the other tabs then the navigation controller will be swapped away and it's navigation bar will no longer be visible. Swap back to tab 4 you'll see it again, complete with it's navigation bar.
I created a sample app in order to confirm what I'm describing, as I haven't used tab bar controllers a lot, and not in quite a while I can upload the project if you really need to see it. It only contains a couple of lines of code (to implement the button on the navigation controller's view controller that creates and pushes a new view controller.)

The TabBarItem disappear when I push in other view

I have a TabBarApplication with four views in the main TabBarItem. The problem comes when I go to any of these views and click in any button to go to another view and when I go back by a button linked to the main view, the TabBarItem of the app disappear!!
For example, one view of the app is a tableView in which each element of the list is linked to his external view and it has a back button that should return to the tableView. All the segues are by modal, not push because push segue crash the application and by modal it runs correctly but the problem comes when I returned by clicking the back button of the NavigationItem in the header of the view to his main view and the TabBarItem of the app is not there, is empty.
Each tab should have the view controller set to a navigation controller, with the view controller you want set as the root view controller of the navigation controller. Now you can use push segues and the standard back button that will be added for you. This will bypass the issue (and work much better for you and users).
You current issue is likely related to not really ever going back. Instead, just always presenting new modal view controllers which replace any existing content on screen.

Master-Detail View, Getting a "back" call in the detail view

What I have is a Master view that is embedded in a nav controller and when you push a button it navigates to a different master view and causes a replace segue for the detail view.
What I would like is when the automatic "back button" is pressed, the detail view goes back to the "title" version which I'm using as a splash screen.
Things I've tried so far
Delegating UINavigationBar
Manually forcing a segue when the Master view associated with it's "linked" detailview goes off screen
Okay, figured it out.
Need to get the "splash page" to call the segue. I did do this, BUT I did it with "replace" type, which doesn't allow for "pop" transitions

Tab bar disappears when trying to go back from new view

I am very new to Xcode and have encountered an issue with my app. I am trying to create a tab bar app. On one of the tabs I have a button that brings the user to a different ViewController. I want to have it so the user can select a button that would return them to the tab that had the button. I tried to set up an action from the button to the previous view (the tabbed screen), however the tab bar disappears. I hope this is makes sense.
Here is a link to a screenshot...
Easiest way to do this is to place a UINavigationController as the root view controller of the TabBarController. You can do this in storyboard by simply ctrl+dragging from the tabbar controller to the navigation controller and adding it as a relationship.
Here's an example using storyboards:
The next step is to set the third controller (in this case the table view controller) to your player view controller class.
Then, you can use the default back button and animation that comes with the navigation controller. If you prefer to hide the navigation bar at the top of the screen, then you can use your custom back button to call
[self.navigationController popViewControllerAnimated:YES];
You can also choose custom animations / segues, etc. but using a navigation controller to help you navigate screens is probably the simplest approach.

Resources