多视图应用问题
|
我想制作多视图应用程序。我的目标是程序启动时加载第一个视图控制器,然后按按钮加载新的标签栏控制器并关闭第一个控制器。我尝试了一下,但没有采取任何措施,但是在加载选项卡栏控制器时,它只会显示一个很小的选项卡,而没有任何选项卡,并且旧的控制器不会消失。
这是我所做的:
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];
}
蓝色类
-- 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];
}
红班
-- 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 个回复
钾涎净介
如果您是我,我将只使用XCode提供的选项卡栏模板。它将自动为您完成。