2011-09-26 56 views
0

我想弄清楚如何使用Jason Morrissey在GitHub上發現的名爲JMTabView的自定義選項卡視圖。 (我試着直接問他,但沒有迴應。)哪裏聲明ViewControllers的自定義選項卡視圖?

我知道如何以編程方式創建UITabBarController並分配視圖控制器。在這個例子中,我無法弄清楚在哪裏聲明我的四個UITableViewController和其他VC的四個選項卡中的每一個。該代碼:

// TabDemoAppDelegate.m -> do I declare them here? 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
TabDemoViewController * demoViewController = [[[TabDemoViewController alloc] initWithNibName:nil bundle:nil] autorelease]; 
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:demoViewController] autorelease]; 
//[self.navigationController setNavigationBarHidden:YES]; 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
[self.window addSubview:self.navigationController.view]; 
[self.window makeKeyAndVisible]; 

return YES; 
} 

// TabDemoViewController.m -> or somewhere in here? 

-(void)addCustomTabView; { // this is a private method 
JMTabView * tabView = [[[JMTabView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - 60., self.view.bounds.size.width, 60.)] autorelease]; 
tabView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; 

[tabView setDelegate:self]; 

UIImage * standardIcon = [UIImage imageNamed:@"icon3.png"]; 
UIImage * highlightedIcon = [UIImage imageNamed:@"icon2.png"]; 

CustomTabItem * tabItem1 = [CustomTabItem tabItemWithTitle:@"One" icon:standardIcon alternateIcon:highlightedIcon]; 
CustomTabItem * tabItem2 = [CustomTabItem tabItemWithTitle:@"Two" icon:standardIcon alternateIcon:highlightedIcon]; 
CustomTabItem * tabItem3 = [CustomTabItem tabItemWithTitle:@"Three" icon:standardIcon alternateIcon:highlightedIcon]; 
CustomTabItem * tabItem4 = [CustomTabItem tabItemWithTitle:@"Four" icon:standardIcon alternateIcon:highlightedIcon]; 

[tabView addTabItem:tabItem1]; 
[tabView addTabItem:tabItem2]; 
[tabView addTabItem:tabItem3]; 
[tabView addTabItem:tabItem4]; 

[tabView setSelectionView:[CustomSelectionView createSelectionView]]; 
[tabView setItemSpacing:1.]; 
[tabView setBackgroundLayer:[[[CustomBackgroundLayer alloc] init] autorelease]]; 

[tabView setSelectedIndex:0]; 

[self.view addSubview:tabView]; 
} 

他提到塊......如果他們是相關的,他們是什麼,這是我在哪裏宣佈風險投資的?如果是這樣,怎麼樣?

// You can run blocks by specifiying an executeBlock: paremeter 
// #if NS_BLOCKS_AVAILABLE 
// [tabView addTabItemWithTitle:@"One" icon:nil executeBlock:^{NSLog(@"abc");}]; 
// #endif 

回答

0

我不熟悉的特定庫,但如果它遵循類似的模式,以UITabViewController我會爲您的標籤創建屬性(如果你需要在以後引用它們)在您的應用程序委託的.h文件中和然後在.m中創建您的實例。如果你只是放置標籤,不需要直接引用它們,你應該能夠在.m中定義它們(可能在applicationDidFinishLaunching中),然後將它們分配爲標籤,並讓標籤控制器從中取出它。

+0

謝謝Greg。我不知道如何將ViewControllers分配給這種情況下的選項卡。 – awDemo

相關問題