现在的位置: 首页 > 综合 > 正文

Hiding the iPhone Tab Bar With TTNavigator

2013年08月29日 ⁄ 综合 ⁄ 共 2256字 ⁄ 字号 评论关闭
TTNavigator is a very powerful manner to control the navigation on your application. This class abstract the navigation and simplifies how you open different screens. Learn more about it on this article: URL-Based Navigation.
Here we'll illustrate one issue that you can found using it with Tab Bar driving applications.
Let's think that you have some mapped View Controller like this:
[map from:@"tt://login/(initWithUser:)"toSharedViewController:[LoginViewController class]];
And later on your application you open this View Controller like this:
-(void)openLoginViewController {       TTURLAction*action =  [TTURLActionactionWithURLPath: [NSStringstringWithFormat:@"tt://login/%@", anUser]];       // Open with URL.       [navigator openURLAction:action]; }
Now, you want that when you open this View Controller, the Tab Bar disappears. And when you exit the Tab Bar automatically appears. Well, UIViewController has one nice property called hidesBottomBarWhenPushed. Set this property to YES and everything just works.
But as you can see, TTNavigator does all the work "under the hood". So you doesn't have access to the View Controller Instance to set this property. Don't panic, if you implemented this class you can simply set this property on your init class like this:
@implementationLoginViewController   -(id)init {      ... Your init Code.      this.hidesBottomBarWhenPushed = YES;      ...  }
The second case is when you don't have access to the implementation of this class, because you're using it from one Static Library or another reason.
Don't panic at all, let's use one different approach on this case.
First, add the TTNavigatorDelegate-p to your interface:
@interfaceLoginViewController <TTNavigatorDelegate> {     ... Interface Code  }
Second, set your class as delegate of TTNavigator. One good place to put this code is your init method:
-(id)init {          ... Your init Code.          [[TTNavigatornavigator] setDelegate:self];          ... }
Third, add the method navigator:willOpenURL:inViewController: to your implementation. This method will be called before the navigator push the view to screen. So you have enough time to configure some properties:
-(void)navigator:(TTBaseNavigator*)navigator willOpenURL:(NSURL*)URL inViewController:(UIViewController*)controller {          controller.hidesBottomBarWhenPushed = YES; }
This is it. One last point, doesn't forget to unset your class as delegate of TTNavigator when you finish. For safety, you doesn't want that your TTNavigator still pointing to one deallocated instance. So, include this code on your dealloc method:
-(void)dealloc {       ... Your dealloc code       [[TTNavigatornavigator] setDelegate:nil];       ....  }

抱歉!评论已关闭.