@classSwitchViewController;
@property (nonatomic,retain)IBOutletSwitchViewController* switchViewCOntroller;
+(AppDelegate*) app;
2.在AppDelegate.m文件中添加,
#import "SwitchViewController.h"
修改didFinishLaunchingWithOptions函数
– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
switchViewCOntroller
switchViewCOntroller
windowswitchViewCOntroller;
backgroundColor
makeKeyAndVisible];
returnYES;
}
添加
+(AppDelegate*) app{
sharedApplication]delegate];
}
3.修改SwitchViewCOntroller类
1.头文件修改成
#import <UIKit/UIKit.h>
@classFirstViewController;
@classSecondViewController;
@interface SwitchViewController :UIViewController{
FirstViewController* firstViewController;
SecondViewController* secondViewController;
}
@property(nonatomic ,retain)FirstViewController* firstViewController;
@property(nonatomic ,retain)SecondViewController* secondViewController;
-(void) initView;
-(void) showFirstView;
-(void) showSecondView;
-(void) removeAllView;
@end
2.m文件中完成添加的方法。
#import "FirstViewController.h"
#import "SecondViewController.h"
-(void) initView{
firstViewController ==nil) {
:@"Main"bundle:nil];
instantiateViewControllerWithIdentifier
}
removeAllView];
insertSubviewatIndex
}
-(void) showFirstView{
firstViewController ==nil) {
:@"Main"bundle:nil];
instantiateViewControllerWithIdentifier
}
removeAllView];
insertSubviewatIndex
}
-(void) showSecondView{
secondViewController ==nil) {
:@"Main"bundle:nil];
instantiateViewControllerWithIdentifier
}
removeAllView];
secondViewController
}
-(void) removeAllView{
view
NSLog(@"%d",t);
];i++) {
objectAtIndex:i]removeFromSuperview];
}
}
5.为两个界面上的按钮分别添加消息响应函数
firstViewController添加
– (IBAction)buttonClick:(id)sender {
switchViewCOntroller
}
secondViewController添加
– (IBAction)buttonClick:(id)sender {
switchViewCOntroller
}
为了大家写代码时能有完整参考,,特传上了源码
不要因为世态变迁而埋怨,不要因为命运多舛而怨恨.