2011-04-21 10 views
0

다중보기 응용 프로그램을 만들고 싶습니다. 내 목표는 프로그램이 첫 번째보기 컨트롤러를로드 한 다음 새 탭 막대 컨트롤러를로드하고 첫 번째 컨트롤러를 닫을 때 버튼을 누르면 실행됩니다. 나는 나 자신을 시험해 본다. 그러나 탭 바 컨트롤러가로드 될 때 탭이없고 작은 컨트롤러 만 나타나면 이전 컨트롤러가 사라지지 않는다. 다중보기 응용 프로그램 문제

내가 무슨 짓을했는지 있습니다 :

SwitchAppelegate

-- Header file -- 
#import <UIKit/UIKit.h> 

@class SwitchClass; 

@interface SwitchAppDelegate : NSObject <UIApplicationDelegate> { 
    SwitchClass *switchClass; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet SwitchClass *switchClass; 

@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; 
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; 
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; 

- (void)saveContext; 
- (NSURL *)applicationDocumentsDirectory; 

@end 

-- Implementation file -- 
#import "SwitchAppDelegate.h" 

@implementation SwitchAppDelegate 


@synthesize window=_window; 

@synthesize managedObjectContext=__managedObjectContext; 

@synthesize managedObjectModel=__managedObjectModel; 

@synthesize persistentStoreCoordinator=__persistentStoreCoordinator; 

@synthesize switchClass; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    [self.window addSubview:[switchClass view]]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

SwitchClass

-- Header file -- 

#import <UIKit/UIKit.h> 
@class BlueClass; 

@interface SwitchClass : UIViewController { 
    BlueClass *blueClass; 
} 

@property (nonatomic, retain) IBOutlet BlueClass *blueClass; 

@end 

-- Implementation file -- 

#import "SwitchClass.h" 
#import "BlueClass.h" 

@implementation SwitchClass 

@synthesize blueClass; 

-(void) viewDidLoad { 
    BlueClass *blue = [[BlueClass alloc] initWithNibName:@"BlueClass" bundle:nil]; 
    self.blueClass = blue; 

    [self.view insertSubview:blue.view atIndex:0]; 
    [blue release]; 

    [super viewDidLoad]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [blueClass release]; 
    [super dealloc]; 
} 

BlueClass

-- Header file -- 

@class RedClass; 

@interface BlueClass : UIViewController { 
    RedClass *redClass; 
} 

@property (nonatomic, retain) IBOutlet RedClass *redClass; 

-(IBAction) switch: (id) sender; 

@end 

-- Implementation file -- 

#import "BlueClass.h" 
#import "RedClass.h" 

@implementation BlueClass 

@synthesize redClass; 

-(IBAction) switch: (id) sender { 
    RedClass *blue = [[RedClass alloc] initWithNibName:@"RedClass" bundle:nil]; 
    self.redClass = blue; 
// self.window.rootViewController = self.tabBarController; 
    [self.view addSubview:blue.view]; 
    [blue release]; 

    [super viewDidLoad]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [redClass release]; 
    [super dealloc]; 
} 

RedClass

-- Header file -- 

#import <UIKit/UIKit.h> 

@interface RedClass : UITabBarController { 

} 

@end 

-- Implementation file -- 

#import "RedClass.h" 

@implementation RedClass 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

답변

1

우선은 AppDelegate에 당신이 SwitchClass의보기를 추가하는 것입니다. 그러나 SwitchClass는 UIViewController 클래스가 아니라 UIView입니다. 그래서 대신에 당신이 같은 rootController로 SwitchClass을 추가해야합니다 : 내가 당신이라면

self.window.rootViewController = self.switchClass; 

난 그냥 엑스 코드에서 제공하는 탭 표시 줄 템플릿을 사용할 수 있습니다. 그것은 자동으로 당신을 위해 그것을 할 것입니다.

+0

감사합니다. –