How to change view controller's title in storyboard - ios

I have a ViewController, which is connected to a UINavigationController, that has two buttons, each one for a specific UITableViewController.
I drag and drop from each button to its corresponding UITableViewController and select show for the seque
the problem is that I can tap on the top of the first UITableViewController and set the name, but I can't do that on the second UITableViewController. my question is that normal?
please notice that the second UITableViewControlelr (Subtitle Cell Table View Controller) doesn't have a come back symbol like the other two do
as I am totally aware that I might need to wait because on swift still not a lot of programmers as in Android, i hope you help me
Updat3 1
I will add screenshot to show you my problem
this is the MainViewController
This is the first UITableViewController (as you see it has a title, which is players)
This is the second UITableViewController (my problem is here I couldn't add a title for it by clicking on the sense on my storyboard)

You need to drag a UINavigationItem into UITableViewController.
Navigation item belongs to a view controller and it is used to show the view controller title on the navigation bar. Every UIViewController has a Navitagtion item assigned to it. Its generated at runtime.
When a View Controller is pushed onto a Navigation Controller, the navigation controller gets the information for title view form the view controllers's Navigation Item.
So if you want to be able to change the title of a View Controller from storyboard, you need to add a Navigation Item in ViewController.
UINavigationController cannot have title changed, because, title belongs to ViewController, and navigation controller just show the relevant title onto its navigation bar.

Related

How to make TabBarController inside another TabBarController in swift storyboard?

I wanna know how to create nested UITabBarControllers in Xcode, I'm using Swift.
My first UITabBarController has two items: Search (UITableView) and Map (MKMapView).
When I hit a cell in my table I wanna go to the second UITabBarController.
This second UITabBarController is the detail page for the clicked cell and must have three items --> Info, Reviews and Contact.
Can anyone explain how to do this? Right now I only have the first UITabBarController and a single view controller for the detail page working.
EDIT: The main problem is that when I nest the UITabBarControllers, my app always shows the items of the first UITabBarController.
Make another Tab View Controller next to it (You should see two tab view controllers on the storyboard), and then inside the Tab View Controller you want the other one in, insert a Container View. After the Container View is in the desired Tab View Controller and sized properly, hold control and drag from the Container View to the other Tab View Controller. After releasing, select embed and you should be good to go! Hope this helps. If it does, please vote this up :)
I found the answer by myself.
Just create a segue between the list view and the second tab controller.
And select on the second tab controller hide bottom bar on push in the attributes inspector.
Drag and drop new tabbarcontroller from stroryboard and from your list view controller ctrl+drag to this newtabbar controller and select show segue. (assuming that you are using navigation controller)

Segue from one ViewController to another ViewController inside a Tab Bar Controller?

In the interface builder I have a UITabBarController and it is set as the initial view controller. From the tab bar controller, I have linked three independent ViewControllers; two UIViewController's and one UITableViewController. I have embedded all three of these views inside UINavigationController's as each of these views will eventually segue to a new view.
Interface Builder
Problem:
I now want to link one of the UIViewController's to the UITableViewController using a button to segue to the table view. This way I can pass information, i.e. func prepareForSegue(), to the table view. I want to maintain the tab bar controller at the bottom, however I do not want to have the ability to go back to the previous UIViewController from the current UITableViewController via a UIBarButtonItem at the the top of the view; That is what the tab bar at the bottom is for.
However every time I segue "Show" the table view (it is actually a segue to the table views navigation controller), the navigation bars at the top and the bottom of the table view disappear. Is there anyway to prevent this from happening?
I have also tried segue "Show" directly to the table view, in which case the tab bar is visible, but then it displays a "back" button at the top of the view to segue back to the sending UIViewController. I am hesitant about accepting a solution that would just hide the back button, because I feel I will run into problems down the road when I want to navigate to a detail view from the table view itself, since I would be bypassing the UITableViewController's UINavigationController.
Any solutions would be greatly appreciated. I have been trying to solve this problem for hours and I'm about to put my head through my computer screen. Also I thought about just using tabBarController?.selectedIndex on the button click to shift to the table view, and then passing the information using NSUserDefaults, but this is out of the question since I would be passing a custom object, and would have to encode and decode every custom field.
I you use a segue to get to it, as you say, you will still be using the UIViewController's UINavigationController which seems a bit messy. So I actually think selectedIndex is probably the best way to go as once you change to the UITableViewController you'll be in the correct navigation stack.
Instead of using NSUserDefaults, why not just reference the UITableView itself from the UIViewController, set the values you want, and then swap to it using self.tabBarController.selectedIndex.
So for your scenario above it, assuming the UITableViewContollrer is the third view in the UITabBarController, you would do something like the following:
Pass whatever you want into the UITabBarController by setting some pre-defined var in it. For example, if there was a String called saveMe in the UITableViewController, then do the following in the UIViewController:
let navController = self.tabBarController?.viewControllers![2] as! UINavigationController
let tableViewController = navController.viewControllers.first as! JarListTableViewController
tableViewController.saveMe = "Saved string here"
Swap to the UITableViewController using:
self.tabBarController?.selectedIndex = 2
The only issue with this is using selectedIndex won't perform a transition animation but not sure if you need this. This link could help if you do.

Using UITableViewController in a navigation bar

I'm new to iOS, but I know the basis. I want to host 3 UITableViewController in a UITabBarController using the storyboard.
I dragged a UITableViewController from the object list(?) and control dragged creating a seguel. Now the tab shows successfully the table view controller.
The issue is the rows are taking the space of the status bar. So I want a navigation bar(?) there, with a title. Since I'm new to iOS I don't know the following:
Given the fact that UITabBarController is the first controller ever, the hosted UITableViewController should not have a back button, obviously. So is it correct to use a navigation bar to display a title (and possible add/edit buttons)
If so, I tried dragging the Navigation Bar but it doesn't work.
What am I missing or doing wrong?
hope this helps
actually it is done for another answer. but it will be handy to u too
You will want to add in 3 UINavigationControllers. Have each tab in the tab bar controller segue to a different navigation controller. Then set the root view controller for each navigation controller to one of the table view controllers.

TUITabBarController inside UINavigationController problems

I want to add UITabBarController as root view of my UINavigation controller. The purpose of that is that I want to make similar navigation as Facebook app: Then user select contact on Contacts tab - pushed view with user details doesn't have TabBar.
So, I have navigation controller, tab bar as a root view or it and couple TableViewControllers inside this UITabBarController.
I have two major issues with that:
I can't assign title for navigation bar for root views of tabbar. If I open contact details I have navigation bar title and no tab bar (as I wanted). But if I select Contacts or Favorites - those views have empty navigation bar title. I've tried to set it on viewDidLoad and viewDidApper without any success
Even worse issue. When I press Favorites table view insets are broken. first cell is under navigation bar. First loaded tableview (in my case Contact) displayed correctly. Adjust scroll view insets is YES for both TableViews.
Update:
Solution storyboard (note property "Hide Bottom Bar on the Push" is switched to YES).
I was also struggling with UITabBarController + UINavigationController issue. When UITabBarController was contained by UINavigationController, content insets were acting really weird.
I would suggest to use navigation controllers inside UITabBarController and when next controller is pushed, set 'hidesBottomBarWhenPushed' on that controller to YES.
This would also solve setting navigation bar title, as navigation controller is closer to view controller. You can just use self.navigationItem.
If you leave it to current setup - UITabController contained within UINavigationController, then you need to modify navigationItem on controllers tabBarController (self.tabBarController.navigationItem). Note that best place for it would be in view controllers 'viewWillAppear' for every controller contained within UITabBarController, as they share one navigation item.

How to create a UIView with NavigationBar and TabBar

I would like to introduce in my app a View that will contains both navigation bar and a tab bar at the bottom. View contains a Table View with multiple entries and once user tap on a cell a push segue takes him to another view with details regarding the cell he has previously tapped. If he decides, user can go back to parent view by tapping on 'Back' button of the navigation bar on top. In addition to this, I would like my view to have a tab bar at the bottom with extra tools for the user. So, if he decides to check the 'Creator' of the app, he can by simply tap on 'Creator' TabBarItem at the bottom.
I would like to ask you what is the best way to achieve the above. I have already tried to use UITabBarController combined with UINavigationController. Didn't achieve what I was looking for because I would like the view with the table on it to be independent from the TabBarController and NOT a part of it (by part I mean by accessible through tabs).
Do you believe a UINavigationController view with UITabBarView would be a better choice?
UPDATE
What I mean by, "independent from the TabBarController and NOT a part of it":
Once the app loaded, I would like to see my main view (with table) contains Navigation Bar on top and Tab Bar at the bottom. However, I don't want to see the first tab of the Tab Bar selected because my main view will not be accessible through tabs of the Tab Bar but through Navigation Bar. If, for example, I am in Main view and tap on 1st tap, I would like to move to another view that will contains some other info.
Option 1:-
Create a tab bar Controller and on that TabbarController assign your navigation Views.
say nav1 with tab1 , nav2 with tab2...
Option 2:-
Create a Navigation View Controller and than add the tabbarcontroller on that navigationView Controller by using addSubView.
So when the user clicks on a row in a table u will go to a different View which doesn't have the TabbarController and when the user comes back he will again see the TabbarController.
This is what I will do:
First I will subclass UITabbarController and create for example ParentTabBarController. This controller will contain all the tabs necessary and what they will do if they are clicked so on.
Next for each viewcontroller I create, I will subclass from this ParentTabBarController so that the tabs are already in. You can add additional functionality or override it depending on your situation.
In your appdelegate pass in a navigation controller and every time push and dismiss the viewcontrollers you created in second step.
Hope this helps..

Resources