2012-09-03 93 views
0

我是xcode开发中的新成员。我想创建一个不使用tabbar应用程序或使用故事板的自定义选项卡栏,我想以编程方式进行编辑。有可能。我已经通过这个Video Tutorial,但是当我试图释放标签时,出现错误。谁能帮me.Here是我的代码,xcode中的自定义tabbar

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

+0

您是否在使用ARC? – MMMM

+0

是的,我正在使用弧 – Shyantanu

回答

0

当使用ARC,你不需要保留或释放了对象。

+0

,但是当我尝试运行时没有任何内容出现。你有没有自定义导航栏的例子。 – Shyantanu

+0

遵循这个:http://www.iphonedevcentral.com/create-uitabbarcontroller/ – Resh32

0

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

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

}

无故事板并没有考虑的UITabBarController在XIB

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

如果你使用ARC,那么只需删除[vc release]; – prashant