@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.homeVC = [[HomeViewController alloc]init];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.homeVC];
self.window.rootViewController = navigation;
return YES;
}
#import "HomeViewController.h"
@interface HomeViewController ()
@end
@implementation HomeViewController
- (void)loadView{
UIView *baseView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];
self.view = baseView;
baseView.backgroundColor = [UIColor purpleColor];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];
button.layer.cornerRadius = 8;
button.backgroundColor = [UIColor greenColor];
[button setTitle:@"push" forState:UIControlStateNormal];
[button addTarget:self action:@selector(pushTV) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)pushTV{
UIViewController *SecondTV = [[SecondViewController alloc]init];
//跳轉至子頁面
[self.navigationController pushViewController:SecondTV animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];
button.layer.cornerRadius = 8;
button.backgroundColor = [UIColor purpleColor];
[button setTitle:@"second" forState:UIControlStateNormal];
[button addTarget:self action:@selector(backTV) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UIButton *saveBtn = [[UIButton alloc]initWithFrame:CGRectMake(125, 200, 150, 40)];
saveBtn.layer.cornerRadius = 8;
saveBtn.backgroundColor = [UIColor orangeColor];
[saveBtn setTitle:@"儲存" forState:UIControlStateNormal];
[saveBtn addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:saveBtn];
}
-(void)backTV{
//導覽列隱藏
if (self.navigationController.toolbarHidden) {
[self.navigationController setToolbarHidden:NO animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}else
{
[self.navigationController setToolbarHidden:YES animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
-(void)saveClick{
//返回首頁面
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end