Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web-like tabs for the iPhone

What is the best approach to implement tabs that look like web applications on the iPhone, like the screenshot below (notice the "Checkin-Info-Friends" tabs)? These are not part of the UIKit standard library, but seems to be very common lately.

I've spent considerable time developing applications for the iPhone, but not developing controls like that one. What would be the best approach here:

  • create a new UIView for each tab content, and add the three subviews to the mainview straight away?
  • create new UIViews only when the user clicks on each of the tabs?
  • Put all the content in a UIScrollView, and just change the page as the user clicks on each tab?

Maybe there are open source controls for this out there? I couldn't find anything.

alt text
(source: foursquaregame.com)

like image 586
Eduardo Scoz Avatar asked Dec 16 '09 14:12

Eduardo Scoz


3 Answers

My approach to a similar problem was to make all 4 (in my case) tab views, but respond to didReceiveMemoryWarning by releasing all but the current tab view. (Then, of course, you must make sure that you create the new view, if it doesn't exist, when the user chooses a new tab.)

I thought this was a good compromise - a speedy reaction to the user at first (and in my case memory footprint is at its lowest at this point in my app), and then a response to low memory to avoid being shot.

like image 142
Jane Sales Avatar answered Sep 30 '22 21:09

Jane Sales


I think it best just to have three UIView* references to the subviews in the parent view or view controller, all initially null, then to have subroutine to hide the other two views if they are visible and either construct and show or just show the new view. Assuming no extraordinary memory requirements.

I think with such a small screen area load/unload concerns at the subview level are unlikely to be a concern, but if the parent views need to be loaded/unloaded, the subviews should all go (be both hidden and unloaded), and on reload, loadView should call the routine described in the last paragraph at startup.

If there is in fact a great deal of memory or resource use by any of the three subviews, then my advice is reversed and each of the subviews and/or any memory-intensive objects behind them should be not only hidden but unloaded whenever possible. I think with your use of Google maps there, a need to unload when hidden might apply to that.

Is this th right point to make? Is there some extra detail I'm missing?

like image 25
martinr Avatar answered Sep 30 '22 21:09

martinr


You can have each tab be a real view controller with nib and everything. The only catch is that you must forward on the standard view controller calls you want to receive (viewWillAppear, etc) but it makes the coding much cleaner since you code just as you would for any other view (although for a smaller space).

You call each controllers "view" property to get out the view, which you add as a subview of a container view you have under the tabs.

like image 29
Kendall Helmstetter Gelner Avatar answered Sep 30 '22 20:09

Kendall Helmstetter Gelner