1

메신저 탭에 의해 호출되는 각 UIViewController 내부에서 UINavigationController를 사용하여 프로그래밍 방식으로 UITabBarController를 수행하려고합니다 ... 모든 것을 읽었습니다 ... 모든 기사를 읽었지 만, 자습서 ive의 100 %는 탐색 모음이 표시TabBarController 및 NavigationController 문제

// 
// 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 

그리고 내가 갖고 싶어 뷰 컨트롤러의 구조 : UITableViewControllers ... 여기에 애플 대리자입니다

// 
// 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 

내가 잘못 뭐하는 거지? IB를 사용하여이 작업을 수행하는 방법을 알고 있지만 이번에는 프로그래밍 방식으로 수행해야합니다 ... 미리 감사드립니다!

+0

. mluThunderCam => MLUThunderCam – coneybeare

답변

6

두 개의 UINavigationControllerUITabBarController의 viewController 여야합니다. 사용자가 지정한 rootViewController와 함께 표시됩니다.

구조는 다음과 같이해야합니다 :

UITabBarController 
     | 
     |____ UINavigationController 
     |    | 
     |   YourViewController 
     | 
     |____ UINavigationController 
     |    | 
     ...   AnotherViewController 

그래서 코드가되어야합니다 : 그것은 이름 클래스에 공통 목표 - C 연습이 문자가 대문자로 시작

- (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]; 
} 
관련 문제