【发布时间】:2011-07-19 22:25:28
【问题描述】:
所以我一直在到处寻找有关如何以语法方式创建 uitabbar 的示例。我尽力从每个示例中获取我需要的内容,并将我希望我的应用程序看起来像这样:一个欢迎屏幕,位于 2-tab 选项卡栏之后。
我有一个用于欢迎屏幕的视图控制器,带有一个 UIButton 可以继续:
-(IBAction)aMethod:(id)sender {
MyTabProjectViewController *controller = [[MyTabProjectViewController alloc] initWithNibName:nil bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
Then in my MyTabProjectViewController.m I do this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Setting up the view
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
//Declaring all view controllers
FirstView *first = [[FirstView alloc] init];
SecondView *second = [[SecondView alloc] init];
//Set titles for the view controllers
first.title = @"First";
second.title = @"Second";
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
UINavigationController *nvc1 = [[UINavigationController alloc] initWithRootViewController:first];
UINavigationController *nvc2 = [[UINavigationController alloc] initWithRootViewController:second];
nvc1.navigationBar.barStyle = UIBarStyleBlack;
nvc2.navigationBar.barStyle = UIBarStyleBlack;
NSArray *controllers = [[NSArray alloc] initWithObjects:nvc1, nvc2, nil];
self.tabBarController.viewControllers = controllers;
[self.view addSubview:tabBarController.view];
}
由于某种原因,没有任何效果。当我单击按钮转到 MyTabProjectViewController 时,我看到一个空白页。
【问题讨论】:
-
我发现你的方法有泄漏,尝试释放控制器[控制器释放];在presentModal之后...
-
使用垃圾收集...没有泄漏 :) 谢谢!
-
你必须释放它,我认为你必须在 contentView、first、second、tabBarController、nvc1、nvc2 和控制器上调用 release;如果您要实例化一个非 ivar,为什么在使用后不释放它?
-
@TommyG iPhone 在设备上没有 GC,除非您使用 ARC?
-
@MCannon ARC 代表什么?
标签: iphone objective-c xcode uinavigationcontroller uitabbarcontroller