Managing a subview shown within several tabs in a tabbed app - ios

I have a tabbed iOS 5 app where I need to keep showing a certain subview when some of the tabs are tapped and become displayed. In the following mockups I try to explain what I need: most of the tabs should keep showing a same subview that is intended to show the status of something concerning the core functionality of the app, whereas there's no need to show such status indicator subview within some of the tabs (for example, a settings tab):
Some of the tabs may also allow to navigate through a hierarchy of views, but the subview must keep visible even if user navigates. How could I manage this scenario? Should I create a separated .nib and UIViewController for the subview, and add/remove it as a subview of the root UITabBarController? Or should I load the .nib from within each tab bar view controller, and handle the subview within the tab's view controller? Or is there another and better way to handle this situation?
Thanks in advance

Separate the subview class and its data model. The subview should listen to changes in the data model and possibly modify the data model. Each tab keeps its own subview, but since all subviews share the same data model, when you update one, you update all.

Related

Keep state of navigation controller and only change view

I have an application with a drop down menu as the titleView of my NavigationController. When a user selects an item of the drop down menu, the entire view should switch contents, however, the NavigationBar should remain the same. The NavigationBar should not have to reload any data and the titleView should remain a drop down menu.
The original view upon opening the app:
The view upon touching the dropdown menu:
I currently see a few ways of going about this:
Set up a UIViewController for each option, perform the segue, and reload the data.
Why this is bad: I will have to set up a segue identifier for each ViewController, meaning if I have 15 options in my drop down menu, I will have 210 segue identifiers laying around. I will also have to reload all of my NavigationBar data.
Why this is good: I will have a clear area to set up each individual view.
Programmatically add and remove UIButtons, UILabels, and UIWhatevers as I need them.
Why this is bad: This will create a lot of code inside just one ViewController and things could get difficult to debug.
Why this is good: The NavigationBar never gets reloaded.
Add a container and embed a unique ViewController for each item as I need it.
Why this is bad: All of my work would still be in the main ViewController and I'd have to manage the logic of the embedded ViewController inside one Controller.
Why this is good: The NavigationBar never gets reloaded.
A completely different method suggested by someone else because I don't know the most efficient way of doing this.
So, in conclusion, what is the most efficient way to maintain state of my NavigationBar when switching my main content in my View?
Option 3 is the best out of the three you listed. Options 1 and 2 will get more and more complicated the more view controllers you want to add. Compare that to UINavigationController, UITabBarController, or UIPageViewController which do not need to be more complicated in order to handle 10 screens vs. 100 screens.
I would suggest creating a custom container view controller (Apple's Reference)
I see 2 immediate approaches to implementing this:
Subclassing UIViewController - this is how Apple's container view controllers are implemented
Subclass UITabBarController - I have done this successfully, subclassing UITabBarController to show a custom tab bar at the top instead of along the bottom.

How to persist a slide-out sidebar menu through entire iOS app

Is there an established solution for how to create and persist a slide out sidebar menu (like on Facebook, or Spotify) so that it appears on any view in your iOS application? I've tried using MMDrawerController, but once i segue from the initial view, I lose the sidebar. I assume this is because I'm transitioning the entire viewController, and not just changing the centerViewController.
Of note, I am using a storyboard in my project, and would like to continue if possible.
If I have a GUI element that I want to persist permanently (or appear and disappear but be shared by multiple view controllers) then I create a root view controller and add the persistent gui elements to it and add a container view as a subclass of the RVC's main view which covers the entire size of the screen.
Then what ordinarily would have been your app's rvc is embedded within this container view.
In the example I've posted there is a UILabel on top of the container which of course could be anything (including a whole hierarchy of views, or another container view with another view controller embedded with in it, whatever you want). You can make it appear or disappear as need be throughout the rest of the program either by creating/destroying it as needed, or fading the alpha to/from 0, or changing the x.y co-ordinates to animate it onto/off of the screen etc.

Designing view on top of multiple embed views

I have the task to design a application that has a main view which is always visible (it has a button on it's bottom side, and when pressed a image displays on top of all views), and a set of TableControllerView's that should appear under it, and the user needs to be able to navigate through them.
I know that you can embed a view inside another, but you cannot refer more than one view to it. The current way I'm trying to do now load one TableViewController inside the embed view, and when the user clicks the cell I manually load the other controller and add it as a child of the main view, which is the RootViewController. The problem with this approach is that the navigation bar gets stuck using the root view controller, so I have to manipulate the main navigation items on each subview transition, and second is that the frame for the second view I load is coming as it had full size, making some cells be under the main view button. This way doesn't uses segues for transition, so it makes the storyboard kinda useless.
I was thinking into using a TabViewController with it's tab hidden, but wanted to ask here for a better solution.
As you discovered, a TableViewController likes to fill up the whole screen (except navigation bars, tab bars, status bar, etc. which are official Cocoa Touch GUIs). When you want a table view to fill only part of the screen, you are supposed to use a UITableView but not a UITableViewController. You set your custom view controller object (subclass of UIViewController, not UITableViewController) as the table view delegate and data source. You will need to duplicate part of the functionality of UITableViewController in your custom view controller, but it's not a lot more than you have to do already to supply the data.
You should probably follow the standard design pattern and have separate view controller objects for each of the "pages" the user can navigate to. You just have a main button and image on each of them. But I could imagine why that might not give you exactly the effect you want.

Persistent header in app with UINavigationController

I have a nice iPhone app built that uses a UINavigationController to navigate through a series of tableviews. I now want to add a persistent banner at the top of all of my views, either above the navigation bar or just below it. I do not want it to scroll with the tableview, so I do not want to make it a custom first row.
Any ideas on the best way to approach this?
What I did to achieve this was to make a new UIView for each of the views that I needed the banner on, and placed the banner in there, and the table or other view below the banner. This doesn't keep the banner there persistently through the transitions which is what I really wanted, but I was able to get a non-scrolling header above my tables.
EDIT:
The "correct" way to do this now would be to have a root view controller that consists of your header, and a container view, and then all of the navigation and content goes inside your container view. Although this does require ios6+
You could customize your navigation bar so that it displays the "classical" bar and then, above or below it, it draws your specific content. See this post for more detail.

How to implement a common background UIView for rest of other views?

In my iPad application I have a menu view in the left side and content view in the right side and a tab bar in the top which has 5 different tabs. Now I want to show different views in the menu view and content view when I change the tabs.
My question here is, I want to have a single instance for all those different views so whenever I click on a tab I should be able to show the corresponding menu and content. And the menu view and content view will have common background. How can I move this common background part into a common viewcontroller/class. And how can I maintain a common instance for all different views?
Please clarify me. If you have doubts in understanding please post it.
Thanks,
durai.
I have created a viewcontroller which creates the basic background view. And wherever I want to show this common view, I will create a respective view controller which is subclasses the above basic view controller.
Thanks.

Resources