Проблема с несколькими приложениями - PullRequest
0 голосов
/ 21 апреля 2011

Я хочу сделать мульти просмотр приложения. Моя цель состоит в том, чтобы при запуске программы загрузить первый контроллер вида, а затем при нажатии кнопки загрузить новый контроллер панели вкладок и закрыть первый контроллер. Я пробую себя и делаю первый шаг, но при загрузке контроллера панели вкладок отображаются только маленькие вкладки без вкладок и старый контроллер не исчезает.

Вот что я сделал:

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 Ответ

1 голос
/ 21 апреля 2011

Во-первых, в appDelegate вы добавляете представление SwitchClass. Но SwitchClass - это класс UIViewController, а не UIView. поэтому вместо этого вы должны добавить свой SwitchClass в качестве rootController, например так:

self.window.rootViewController = self.switchClass;

На вашем месте я бы использовал шаблон панели вкладок, предоставляемый XCode. Он сделает это автоматически.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...