Pau*_*ira 1 iphone objective-c uitabbarcontroller uinavigationcontroller
我尝试使用的标签...什么都试过叫各的UIViewController内一个UINavigationController ...阅读每一篇文章编程做的UITabBarController ...但香港专业教育学院的教程100%发现使用在UITableViewControllers ...这里是应用程序代表:
//
// mluThunderCamAppDelegate.m
// mluThunderCam
//
// Created by Paulo Ferreira on 11/9/09.
// Copyright MobileLifeUtils.com 2009. All rights reserved.
//
#import "mluThunderCamAppDelegate.h"
@implementation mluThunderCamAppDelegate
@synthesize window, tbcMain;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
UINavigationController *ncLocal;
mluThunderCam *vcThunderCam = [[mluThunderCam alloc] init];
ncLocal = [[UINavigationController alloc] initWithRootViewController:vcThunderCam];
[ncLocal release];
mluThunderCamPreferences *vcThunderCamPreferences = [[mluThunderCamPreferences alloc] init];
ncLocal = [[UINavigationController alloc] initWithRootViewController:vcThunderCamPreferences];
[ncLocal release];
NSArray *aViewControllers = [[NSArray alloc] initWithObjects:vcThunderCam, vcThunderCamPreferences, nil];
[vcThunderCam release];
[vcThunderCamPreferences release];
tbcMain = [[UITabBarController alloc] init];
tbcMain.viewControllers = aViewControllers;
[aViewControllers release];
[window addSubview:tbcMain.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
并且我想要显示导航栏的视图控制器的结构:
//
// mluThunderCam.m
// mluThunderCam
//
// Created by Paulo Ferreira on 11/10/09.
// Copyright 2009 MobileLifeUtils.com. All rights reserved.
//
#import "mluThunderCam.h"
@implementation mluThunderCam
-(id) init {
self.title = @"Home";
self.navigationItem.title = @"Damn!";
return self;
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
UIView *vwThunderCam = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = vwThunderCam;
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么??我知道如何使用IB这样做,但这次我需要以编程方式做到这一点...提前致谢!
你的两个UINavigationController应该是viewControllers UITabBarController.它们将显示您为其分配的rootViewController.
结构应该是这样的:
UITabBarController
|
|____ UINavigationController
| |
| YourViewController
|
|____ UINavigationController
| |
... AnotherViewController
所以你的代码应该是:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
mluThunderCam *vcThunderCam = [[mluThunderCam alloc] init];
UINavigationController *nav1; = [[UINavigationController alloc] initWithRootViewController:vcThunderCam];
[vcThunderCam release];
mluThunderCamPreferences *vcThunderCamPreferences = [[mluThunderCamPreferences alloc] init];
UINavigationController *nav2; = [[UINavigationController alloc] initWithRootViewController:vcThunderCamPreferences];
[vcThunderCamPreferences release];
NSArray *aViewControllers = [[NSArray alloc] initWithObjects:nav1, nav2, nil];
[nav1 release];
[nav2 release];
tbcMain = [[UITabBarController alloc] init];
tbcMain.viewControllers = aViewControllers;
[aViewControllers release];
[window addSubview:tbcMain.view];
[window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
946 次 |
| 最近记录: |