0

I have a Tab Bar app with 4 views. One of the views (Notes) is a UITableView embedded in a UINavigationController (since the "note" UIViewController can show and edit cell details)

I have built all of this in the layout editor to avoid assumptions about segues and controllers. I have added Title and Image attributes to the relevant UIViewControllers (and in the case of the UITableView the UINavigationController.)

The Image and Title of the "Notes" tab shows up properly in the layout editor, and the other 3 tabs show up fine when the app runs, but when the app runs the title for the note tab is replaced with the string "item". The odd thing is that the Image shows up fine. If I segue straight to a UITableViewController it works - but of course I need a NavigationController for my TableView - so that's no help.

Here's the relevant XIB code:

   <!--Notes Navigation-->
    <scene sceneID="gSO-qG-y5n">
        <objects>
            <navigationController id="Q9R-oO-LQa" userLabel="Notes Navigation" sceneMemberID="viewController">
                <tabBarItem key="tabBarItem" tag="1" title="Notes" image="Note" id="gFR-SE-gGB" userLabel="Notes"/>
                <navigationBar key="navigationBar" contentMode="scaleToFill" id="oNo-5Q-VaO">
                    <rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
                    <autoresizingMask key="autoresizingMask"/>
                </navigationBar>
                <connections>
                    <segue destination="SCr-y6-ymj" kind="relationship" relationship="rootViewController" id="vnz-pl-Fkb"/>
                </connections>
            </navigationController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="Bvb-jZ-wUu" userLabel="First Responder" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="-523" y="2538"/>
    </scene>

It's the title="Notes" tabBarItem attribute that's not being honored. image="Note" is being honored. It can't be a problem with the layout being corrupted since this XIB code looks perfect - so I'm stumped.

As I said - everything functions perfectly - it's just this title being displayed as "item" that's the problem.

In the meantime, I suppose I'm going to have to set the title in code. This is being developed in Swift with XCode 6.3.

Where would be a proper place to put this in my app?

  • It could be that the TabBarItem is acquiring the title of the nav controller or the root controller in your UINavigationController which overrides what you set for the tab itself. I believe this might be normal behaviour. Check the title for the UINavigationController in the attribute inspector and UINavigationItem title on your root controller. One has probably been set to "item" when you connected it up. – Rory McKinnel Apr 22 '15 at 14:23
  • No, that;s a good thought, but I set the navigation controllers' titles to "foo" to test that theory. Nobody inherits "foo" – Erick Kobres Apr 22 '15 at 15:45
  • I posted an answer with more detail and a link to a discussion on it. Odd as I thought that should work. When I did a test, I found the title of the nav controller showed on the top of the storyboard image as "item" which fits with what you are seeing. – Rory McKinnel Apr 22 '15 at 15:53
  • Mine is getting set to "Item" with a capital "I." What's really strange is that IB shows everything correctly since I did set the tab bar item in the navigation controller with the correct title and image. – Erick Kobres Apr 22 '15 at 16:11

3 Answers3

0

Set the title directly on the other view.

// Create a new TabBarItem then assign it. 
var tabBarItem = UITabBarItem(title: "Something", image: YOURIMAGE, tag: 0)
self.navigationController?.tabBarItem = tabBarItem

or

self.navigationController?.tabBarItem.title = "Something"
Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • Where would I set this? I need for the tab bar to show the right title before the tab bar controller becomes visible - so I feel like my only safe option is in the AppDelegate. – Erick Kobres Apr 22 '15 at 16:09
  • Your other viewController. YourUITabBarController will load it's subviews and on those views is where you set the title. Do this on your viewController that has the navigation controller. – Mark McCorkle Apr 22 '15 at 16:19
  • Do this in your viewWillAppear on the problem viewController. – Mark McCorkle Apr 22 '15 at 16:26
  • It's not a problem with the viewController - its a problem with the top level tab bar controller (UITabBarController) which segues to the other views. Unfortunately waiting until the incorrectly attributed view loads or willAppear is way too late to keep the wrong text from being visible. Fortunately this only happens for me in the simulator - it works properly on real hardware - so I'm going to stop trying to fix it. I was able to "force" it by walking the items in 'AppDelegate.applicationDidBecomeActive()'. – Erick Kobres Apr 22 '15 at 16:56
  • The viewController itself has nothing to do with what I posted. That is simply where you get the reference to the UITabBarItem of the naivigationController (i.e. your tab bar). But yes, if there is no problem(question) then I'd recommend deleting the question. – Mark McCorkle Apr 22 '15 at 18:03
0

I think the TabBarItem is acquiring a default title of the navigation controller which shows as "item" when you add one in storyboard. I just tried this with a new tab bar adding a UINavigationController as an item.

To set the title to what you want, click on the UINavigationController in storyboard and set the Title field in the attribute inspector to the title you want. The tab bar will then use this title when you run it.

This is not the same as the navigation item title which is the title on the navigation bar.

See: self.title sets navigationController and tabBarItem's title? Why?

Community
  • 1
  • 1
Rory McKinnel
  • 7,936
  • 2
  • 17
  • 28
  • Unfortunately no. See the comment above. A search for "Item" in the XIB yields no results - yet a search for "Notes" shows my navigationController title - so IB can't be the one responsible for putting that text in there. – Erick Kobres Apr 22 '15 at 15:57
  • The default label is "Item" when you create a new entry. However when I change it everything works fine. Since it happens when you run, have you tried doing a clean/build, deleting the app from the simulator/device, then running. Just in case its a hangover from a previous install affecting the storyboard. I have had this before for layout and other storyboard items not working quit right until I fully deleted the app. – Rory McKinnel Apr 22 '15 at 16:47
0

This appears to be a bug that either affects the simulator or the version of iOS running on the simulator.

If I run on the iPhone 6 simulator, I get the bad behavior. If I run on an actual iPhone 6 with iOS 8.3, everything works as expected.

The correct place for me to set it ended up being where I started - which is in the tab bar item of the navigation controller.

Cheers and thanks for all of the other suggestions.