xcode中的自定义tabbar

时间:2012-09-03 13:31:17

标签: iphone xcode4.2

我是xcode开发的新手。我想创建一个不使用tabbar应用程序或使用故事板的自定义选项卡栏,我想以编程方式进行。有可能吗?我已经完成了这个Video Tutorial但是当我试图发布标签时,会出现错误。任何人都可以帮助我。这是我的代码,

main_tab = [[UITabBarController alloc] init];
    viewController1 = [[Firstview alloc] init];
    viewController1.title = @"View 1";
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

    viewController2 = [[SecondView alloc] init];
    viewController2.title = @"View 2";
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:viewController2]; 

我正在使用xcode 4.2

3 个答案:

答案 0 :(得分:0)

使用ARC时,您不再需要保留或释放对象。

答案 1 :(得分:0)

您可以通过单击项目文件并选择相应的属性来启用或禁用ARC。 Here你有一个很好的描述。

答案 2 :(得分:0)

如果您使用的是故事板,则应该有起点。 所以以故事板中的uitabarcontroller为起点,并链接对tabBarController的引用

 NSMutableArray *listOfViewControllers = [[NSMutableArray alloc] init];
UIViewController *vc;

vc = [[UIViewController alloc] init];
vc.title = @"A";
[listOfViewControllers addObject:vc];
[vc release];
vc = [[UIViewController alloc] init];
vc.title = @"B";
[listOfViewControllers addObject:vc];
[vc release];
vc = [[UIViewController alloc] init];
vc.title = @"C";
[listOfViewControllers addObject:vc];
[vc release];

[self.tabBarController setViewControllers:listOfViewControllers
                                 animated:YES];

}

没有故事板,也没有在XIB中使用UITabbarController

UITabBarController *tabBarController = [[UITabBarController alloc] init];

NSMutableArray * listOfViewControllers = [[NSMutableArray alloc] init];     UIViewController * vc;

vc = [[UIViewController alloc] init];
vc.title = @"A";
[listOfViewControllers addObject:vc];
[vc release];
vc = [[UIViewController alloc] init];
vc.title = @"B";
[listOfViewControllers addObject:vc];
[vc release];
vc = [[UIViewController alloc] init];
vc.title = @"C";
[listOfViewControllers addObject:vc];
[vc release];

[tabBarController setViewControllers:listOfViewControllers
                                 animated:YES];
相关问题