在哪里为自定义选项卡视图声明ViewControllers?

时间:2011-09-26 15:46:47

标签: objective-c ios cocoa-touch uitabview

我正在试图弄清楚如何使用Jason Morrissey在GitHub上发现的名为JMTabView的自定义标签视图。 (我试着直接问他,但没有得到回应。)

我知道如何以编程方式创建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];
}

他提到了块......如果它们是相关的,它们是什么,这是我在哪里声明VC?如果是这样,怎么样?

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

1 个答案:

答案 0 :(得分:0)

我不熟悉那个特定的库,但是如果它遵循与UITabViewController类似的模式,我会在你的App Delegate的.h文件中为你的标签创建属性(如果你需要稍后引用它们),然后创建你的实例在他们中。如果您只是放置选项卡而不需要再直接引用它们,您应该能够在.m中定义它们(可能在applicationDidFinishLaunching中),然后将它们分配为选项卡,让选项卡控制器从那里获取它。 / p>