单击TTTabIcon时打开UIViewController

时间:2011-03-21 19:25:18

标签: iphone url uiviewcontroller three20

当我在TTTabItem上选中时,你能告诉我如何打开UIViewController吗?

URL映射在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]];

然后在我的视图控制器中,我已成功添加了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];

我现在如何使用TTURLMap在TTTabStrip下面打开另一个uiviewcontroller?

谢谢,doonot

1 个答案:

答案 0 :(得分:0)

好的,我必须先将我的视图控制器设置为委托:

- (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];
}

然后,如果你点击一个TTabItem,委托调用这个函数:

- (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];
        }
    }

列表中的第一项当然是索引为0的项目。现在您可以在app delegate中定义url映射。例如tt:// ajax calles SponsorController:

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

ajax在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]];

我希望得到帮助。真的很糟糕,那里几乎没有例子或教程。干杯