datwelk
datwelk

Reputation: 1037

Navigation style like in Twitter for iPhone

I'm trying to figure out how the navigation style in Twitter for iPhone has been implemented.

When you tap a tweet in the timeline, the (custom) tab bar stays in place during the transition from timeline to detail view. This suggests that the tab bar is a subview of the 'main' UIViewController, which contains an array with 4 UINavigationControllers, one for each tab. When a tab is pressed, the main UIViewController removes the currently visible UINavigationController from its view and adds the new one as subview. In this approach the tab bar is not part of any navigation stack, thus it stays in place during each transition.

However, when you tap a URL in the detail view, the tab bar moves off-screen and a new toolbar appears. This contradicts the theory described above.

Tweetbot uses exactly the opposite navigation style of the official Twitter app. If you tap a tweet in Tweetbot's timeline, the tab bar does move off-screen. The tab bar never stays in place during a transition. They probably use one UINavigationController, with the main UIViewController + tab bar as rootviewcontroller. I assume that the timeline calls [self.navigationController pushViewController:] on the main UIViewController via delegation or something similar when the user taps on a tweet.

In fact, Twitter for iPhone mixes the first theory with the theory behind Tweetbot's navigation style. How can I achieve what the official Twitter app does?

Upvotes: 2

Views: 503

Answers (1)

Ben Sandofsky
Ben Sandofsky

Reputation: 1190

This may be an overly simplified description, and a lot is going by memory, but I think this should get you on your way…

The root view controller is mostly a tab bar controller implemented from scratch. It was originally for custom tab bar styling before there were easy iOS APIs. However, by continuing to own the code, it wasn't too difficult to add a toolbar/tab bar swap.

The root view controller owns both the tab bar view and the toolbar view. The root view controller is a delegate of each tabs' navigation controllers; when a navigation controller pushes the new view controller, the main view controller checks whether it has toolbarItems, and manages the swap.

For usability reasons, it's usually a bad idea to replace the tab bar with a tool bar. Tab bars provide grounding to the onscreen content; think tabs of your browser. Tab bar items also let you jump to the root view controller in the hierarchy by tapping it while the tab is active. (It isn't the most discoverable feature, but at least it's standard system-wide.)

This isn't a hard fast rule. It's common to replace the tab bar for "leafs" in your navigation hierarchy; think Music.app, and Photos.app. Just avoid it unless you have a strong compelling reason.

Upvotes: 2

Related Questions