【问题标题】:Open UIViewController when clicking on TTTabIcon点击 TTTabIcon 时打开 UIViewController
【发布时间】:2011-03-21 19:25:17
【问题描述】:

你能告诉我当我在 TTTabItem 上标签时如何打开 UIViewController 吗?

URL 映射在应用委托中完成:

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?

谢谢,不要

【问题讨论】:

    标签: iphone url uiviewcontroller three20


    【解决方案1】:

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

    - (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 委托中定义 url 映射。例如 tt://ajax 调用 SponsorController:

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

    ajax 在应用委托中定义:

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

    我希望这会有所帮助。真的很糟糕,那里几乎没有示例或教程。干杯

    【讨论】:

      猜你喜欢
      • 2018-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多