0

我试图弄清楚如何使用我JMTabView在 GitHub 上找到的由 Jason Morrissey 调用的自定义选项卡视图。(我试着直接问他,但没有得到回应。)

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

1 回答 1

0

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

于 2011-09-26T17:05:37.000 回答