Refactoring storyboard, results in navigation controller dependent scene navigation items to disappear but still working - ios

I use Xcode 9.2 and iOS 10.x.
I would like to refactor my large main storyboard to smaller ones.
My initial login scene is embedded in a navigation controller, so all other consequating scenes are in the navigation stack and I have created view controller titles and navigation bar buttons to them.
After refactoring a branch of my scenes that are related to staff management to a new storyboard, everything has been moved correctly and links between storyboards created and the application still working as expected. I did the refactoring using Editor-->Refactor to Storyboard...
However, when you go to the editor of the new Staff storyboard you will notice that all navigation headers and buttons are missing, although working. For example, in the first scene I have a title and in the 2nd screen of the stack I have several nav bar items. All of these are missing in editor but appear when I run my application.
Does anybody knows how I can make navigation items visible again, in my new Staff storyboard, in order to edit them further e.g. add new buttons etc. ?
Is there any fix to all of this or is it a normal feature of Interface Builder/Xcode?
An oversimplified "version" of this issue could be recreated as follows:
1. you have just one view controller A embedded in a Navigation Controller.
2. you add navigation items / nav bar buttons in the navigation bar
3. you remove the navigation controller and as a result you loose in the editor any buttons

Related

Where is UINavigationItem disappearing to when refactoring views to storyboard?

I'm rewriting an Obj-C project using Swift 4 / Xcode 9.2
I have a large storyboard that I am breaking down into multiple storyboards. I did this previously without any issues. If I refactored a few views to their own storyboard then the views took the navigation item with them. now they disappear...
[
My questions are ...
Is this an Xcode bug? or a new feature?
Obviously you can work around this as I have shown in the pictures but is there a way to stop the vanishing from happening?
This is the way it's always been. In your storyboard, if a view controller is not a child of a navigation controller via root view controller or push segues, then by default no navigation bar is shown in the storyboard. You can force it on, though, by going to the Simulated Metrics section of the Attributes Inspector tab and selecting one of the navigation bar options for "Top Bar".
Your view controller is no longer a child of a navigation controller, so it no longer automatically has a navigation item. If you need it to have a navigation item, drag a Navigation Item from the Object Library onto it. You will then be able to give the navigation item a title, and drag buttons and so forth onto the navigation item.

Xcode 6 - Swift - Custom Tabbar with Navigation

I'm trying to create a tabbed application with navigation elements inside the tab bar, as seen in the picture below (the red bar) using Swift/XCode 6.2. Basically those three icons in the middle will direct the user to different view controllers. The other two icons would be context-based. For example, on a table view page you would see the menu icon and add new icon as seen in the image. However, clicking on a row would change the menu icon to a back icon, and the add icon to something else.
That's the general idea, but I'm having a very hard time implementing something even close to this. The first issue is that whenever I embed a view in a Tab Bar Controller, I can't move the tab bar to the top. However, when I create a custom UITabView in a View Controller, Control + Click and dragging a Tab Bar Item to another view doesn't create a segue. I haven't even begun to tackle having the navigation elements inside the bar.
I guess what I'm asking is just for a little guidance on what route to take to tackle this. I'm assuming I can't use a Tab Bar Controller or Navigation Controller because it doesn't seem like I can customize them all that much. So custom Tab Bar and Navigation Bars, and then implemnt the segues and button changes programmatically?
Thanks.
I will try to guide you from an architectural perspective (so you won't find much code below).
Using a UITabBarController
In order to achieve what you are suggesting, you are right you cannot use a UITabBarController straight away, among several reasons, the most immediate one is that they are meant to be always at the bottom and you want it in top (check Apple's docs). The good news is that probably you don't need it!
Note: If you still want to go with a UITabBarController for whatever reason, please see #Matt's answer.
Using a UINavigationController
You can use a UINavigationController to solve this task, since the UINavigationBar of a UINavigationController can be customized. There are multiple ways on how you can organize your view's hierarchy to achieve what you propose, but let me elaborate one option:
To customize a UINavigationBar's to add buttons, you just need to set its navigationItem's title view:
// Assuming viewWithTopButtons is a view containing the 3 top buttons
self.navigationItem.titleView = viewWithTopButtons
To add the burger menu functionality on a UINavigationController you can find several posts on how to do it and infinite frameworks you can use. Check this other SO Question for a more detailed answer (e.g. MMDrawerController, ECSlidingViewController to mention a couple).
About organizing your view hierarchy, it really depends on if when the user taps one of the main top buttons, it will always go to the first view controller in the new section or if you want to bring him back to the last view in the section where he was.
3.1 Switching sections displays the first view of the new section
Your app's UIWindow will have a single UINavigationController on top of the hierarchy. Then each of the 3 top buttons, when tapped, will change the root view controller of the UINavigationController.
Then, when the user changes section, the current navigation hierarchy is discarded by setting the new section view controller as the UINavigationController root view controller.
self.navigationController = [sectionFirstViewController]
3.2 Switching sections displays the last displayed view in the new section
This will require a slightly modified version of the above, where your each of your sections will have its own UINavigationController, so you can always keep a navigation hierarchy per section.
Then, when the user taps one of the top buttons to switch section, instead of changing as previously described, you will change the UIWindowroot view controller to the new section's UINavigationController.
window.rootViewController = sectionNavigationController
Using a custom implementation
Of course, the last and also very valid option would be that you implement yourself your own component to achieve your requirements. This is probably the option requiring the biggest effort in exchange of the highest customizability.
Choosing this option is definitely not recommend to less experienced developers.
I'd like to take a stab at this--I think it is possible to use a tab bar controller here.
Your topmost-level view controller will be a UITabBarController with a hidden UITabBar.
Each tab is contained in a UINavigationController.
All view controllers in the navigation controller will be a subclass of a view controller (say, SwitchableViewController).
In SwitchableViewController's viewDidLoad, you set the navigation item's title view (i.e. whatever's at the center; self.navigationItem.titleView) to be the view that holds the three center buttons. Could be a UISegmentedControl, or a custom view.
Whenever you tap on any of the buttons, you change the topmost UITabBarController's selected index to the view controller you want to show.
Issues you may encounter:
Table views inside tabs will have a scrollIndicatorOffset at the bottom even if the tab bar is hidden.
Solution: Play around with the automaticallyAdjustsScrollViewInsets of the tab bar controller, or the inner view controller. https://stackoverflow.com/a/29264073/855680
Your title view will be animated every time you push a new view controller in the navigation stack.
Solution: Take a look at creating a custom transition animation for the UINavigationController.

iOS 8 Navigation Bar Not Accessible in Second ViewController on Storyboard

I am new to iOS development and have not tried this programmatically yet. I would prefer to get this working in a storyboard.
I'm following this somewhat outdated tutorial from XCode 4.5 in XCode 6.1 to create a series of views connected by one navigation controller.
http://youtu.be/rgd6mCuzlEc
Once I create the second view controller, I am unable to double click the navigation bar to change the name and I am unable to add a bar button to it.
I have a Segue going from bar button "Item" from view 1 to 2. Notice in the "View Controller Scene" there is no navigation item. If I add any elements to the view controller they fall under "View" and not under "View Controller", unlike view controller 1 where it falls under "one".
Is this a limitation on XCode? Am I using the wrong Segue (Show)? Is there a hidden setting or customization I'm missing?
I actually have this working for 2 view controllers and failing the 3rd in a separate project but I don't know what I did to do that so I'm pretty sure it's possible I just cannot reproduce..
EDIT: Workaround Instead of the new adaptive SHOW segue, use the deprecated PUSH segue, add the bar button items, then change back to the adaptive SHOW segue.
Try adding a Navigation Item to the controller and it should work properly

Can't add navigation bar to scene: Root view controller issue?

I'm still struggling with navigation bars and just can't work out how to edit or verify that I have a navigation bar on my view and I would appreciate any help.
I have a project with another set of scenes similarly comprising of a navigation controller and three associated view controllers (connected via segues and main table view embedded in the navigation controller) and I was able to add a navigation bar manually in interface builder to the outer view controllers that were segued to the table view controller.
But in this set of scenes the navigation controller is set up as the root view controller for the table view.
I have another set of scenes. A navigation controller and two related view controllers - both table view controllers. I embedded the first table view controller in the navigation controller and I then added a second table view controller to this (for a new screen I want to add to my app) and I connected this second table view controller to my first table view controller by way of a show segue (just like I did yesterday with other set of scenes).
Can I set this other navigation controller as the root controller also?
Like, can I have two root view controllers in a project?
It looks to me like there is a navigation bar visible (see screenshot below) on my new table view controller but I can't click in to it to edit it to add a title to it.
But does a navigation bar and exist, and if so, why can't I click inside it and use it?
I was told in an answer to a previous question that you have to add a navigation bar manually to your storyboard scene to any additional view controllers. I did that yday and it worked. But today when I tried to add a navigation bar by dragging onto scene it wouldn't let me do this.
Here is the screenshot:
Try adding push segue(which is depreciated) and than change it to a show segue(between your tableviews). This is a workaround I use in my apps.
Ran into the same problem. Had a good fallback position, I am doing a tutorial that came with example programs completed and working so the first thing I did was see if it was a version glitch between 6.3.2 and 6.4. Turned out the earlier project worked just fine.
So what I did was simply drag the 'Item' in the sidebar and moved it under the Root View Controller!
I've experienced the same issue.
However, by saving and closing the project then reopening it, the Navigation Bar title is then able to be edited. Prior to closing/reopening the project the field could not be edited.

ios: storyboard + tabbar + more button (design)

I have a little app that shows a list of dvds, then you can drill down from the table view and get some details. It also has a tab bar at the bottom and you can switch from dvds to bluray as tab buttons. This all works fine.
In reading about tab bar apps, I saw a demo that once you added more than 5 tab bar buttons, "more" would show up and then you can drag-n-drop the buttons like in Apple's Music app, which is cool! I also noticed that each tab bar button controlled a separate navigation controller, which was a new technique to me.
When I created my app, it had a single navigation controller and I added a view controller with the top of the view being a table view and the bottom of the view a tab bar. I then drag buttons to the button bar and can add more than 5 buttons and "more" doesn't show up.
So, I figure, it needs to to be a different navigation controller design.
I am confused on if I can take my app and embed a tab view controller or if I can adapt what I have or not.
Right now, since all tabs are basically the same (a table that drills down to a detail view) I just reload the data from a different file when the tab is switched. Nice and clean.
If I switched to the tab view controller concept, it seems wasteful to create 5 navigation controllers with 5 table views that drill down to 5 detail views. Plus what if I wanted 7? or 9? (I do realize (or guess) that I can give each 5 views the same class name, but still the UI has lots of storyboards…)
This is a design question to better understand what my options are.
Tab bar controller must always be the root controller of an application. (Unless it's in a split view, in which case the different sides of the split can be a tab bar controller - but it still has to be the root.)
So, the correct design for your app is: tab bar controller as root, each tab containing a navigation controller, each navigation controller having your table view controller as the first view controller. It may seem wasteful but if you think about it, each tab really needs to have its own stack of controllers, so there's no other reasonable way to do it. If user on tab 1 is 2 deep in a nav stack but tab 2 is 7 deep you don't want to switch between tabs and lose your place.

Resources