开发者

Open UIViewController when clicking on TTTabIcon

开发者 https://www.devze.com 2023-02-19 06:04 出处:网络
can you tell me how I can open a UIViewController when I tab on a TTTabItem? URL mapping is done in the app delegate:

can you tell me how I can open a UIViewController when I tab on a TTTabItem?

URL mapping is done in the app delegate:

TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
na开发者_JAVA技巧vigator.persistenceMode = TTNavigatorPersistenceModeAll;

TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://mannschaft" toViewController:[MannschaftController class]];

Then in my view controller I have successfully added my TTTabSTrip:

CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;

self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
self.view.backgroundColor = TTSTYLEVAR(tabTintColor);

_tabBar = [[TTTabStrip alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, 41)];
_tabBar.tabItems = [NSArray arrayWithObjects:[[[TTTabItem alloc] initWithTitle:@"Anno 1834"] autorelease], nil];
[self.view addSubview:_tabBar];

How can I now open another uiviewcontroller below the TTTabStrip using the TTURLMap?

Thanks, doonot


Ok, I had to set my view controller as delegate first:

- (void)loadView {
    CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;

    self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
    self.view.backgroundColor = TTSTYLEVAR(tabTintColor);

    _tabBar = [[TTTabStrip alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, 41)];
    _tabBar.tabItems = [NSArray arrayWithObjects:[[[TTTabItem alloc] initWithTitle:@"Ajax Wälläbärg"] autorelease], nil];
    _tabBar.delegate = self; 
    [self.view addSubview:_tabBar];
}

Then, if you click on a TTabItem, delegate calls this function:

- (void)tabBar:(TTTabBar*)tabBar tabSelected:(NSInteger)selectedIndex   {
        TTTabItem *tabItem = [tabBar.tabItems objectAtIndex:selectedIndex];
        NSLog(@" tabItem:%@, tabItem.title::%@", tabItem, tabItem.title); 

        if(selectedIndex == 0){
            UIViewController* viewController = [[TTNavigator navigator] viewControllerForURL:@"tt://ajax"];
            [self.view addSubview:viewController.view];
            [self.view addSubview:_tabBar];
        }
    }

The first item in the list is of course the item with index 0. Now you can define the url mapping in app delegate. For example tt://ajax calles the SponsorController:

UIViewController* viewController = [[TTNavigator navigator] viewControllerForURL:@"tt://ajax"];

ajax is defined in app delegate:

TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;

TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://mannschaft" toViewController:[MannschaftController class]];
[map from:@"tt://ajax" toViewController:[SponsorController class]];

I hope that helpes. Really bad that there are hardly no examples or tutorials out there. Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消