IOS学习 NSNavigationController 多个子页面间相互跳转
来源:互联网 发布:淘宝v达人 编辑:程序博客网 时间:2024/05/19 16:50
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.homeVC = [[HomeViewControlleralloc]init];
UINavigationController *navigation = [[UINavigationControlleralloc]initWithRootViewController:self.homeVC];
self.window.rootViewController = navigation;
self.window.backgroundColor = [UIColorpurpleColor];
return YES;
}
@implementation HomeViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [[UIButtonalloc]initWithFrame:CGRectMake(100,100, 200, 40)];
button.layer.cornerRadius =8;
button.backgroundColor = [UIColorgreenColor];
[button setTitle:@"push"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(pushVC)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
-(void)pushVC{
UIViewController *secondVC = [[SecondViewControlleralloc]init];
secondVC.view.backgroundColor = [UIColorcyanColor];
//跳转至子页面
[self.navigationControllerpushViewController:secondVC animated:YES];
}
@implementation SecondViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [[UIButtonalloc]initWithFrame:CGRectMake(100,100, 200, 40)];
button.layer.cornerRadius =8;
button.backgroundColor = [UIColorpurpleColor];
[button setTitle:@"second"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(backVC)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
UIButton *button2 = [[UIButtonalloc]initWithFrame:CGRectMake(100,200, 200, 40)];
button2.layer.cornerRadius =8;
button2.backgroundColor = [UIColororangeColor];
[button2 setTitle:@"push"forState:UIControlStateNormal];
[button2 addTarget:selfaction:@selector(pushVC3)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button2];
}
-(void)backVC{
//导航栏隐藏
if (self.navigationController.toolbarHidden) {
[self.navigationControllersetToolbarHidden:NOanimated:YES];
[self.navigationControllersetNavigationBarHidden:NOanimated:YES];
}else
{
[self.navigationControllersetToolbarHidden:YESanimated:YES];
[self.navigationControllersetNavigationBarHidden:YESanimated:YES];
}
}
-(void)pushVC3{
UIViewController *threeVC = [[ThreeViewControlleralloc]init];
threeVC.view.backgroundColor = [UIColoryellowColor];
//跳转至子页面
[self.navigationControllerpushViewController:threeVC animated:YES];
}
@implementation ThreeViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
NSArray *array =@[@"push",@"pop",@"root",@"index"];
for (int i=0; i<4; i++) {
UIButton *button = [[UIButtonalloc]initWithFrame:CGRectMake(100,100*(i+1), 200, 40)];
button.layer.cornerRadius =8;
button.backgroundColor = [UIColorredColor];
NSString *str = array[i];
button.tag = i+1;
[button setTitle:strforState:UIControlStateNormal];
[button addTarget:selfaction:@selector(backVC:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
}
- (void)backVC:(UIButton *)sender{
switch (sender.tag) {
case 1:
//push 至子页面
threeVC.view.backgroundColor = [UIColoryellowColor];
threeVC = [[ThreeViewControlleralloc]init];
[self.navigationControllerpushViewController:threeVCanimated:YES];
break;
case 2:
//pop 返回至上一页面
[self.navigationControllerpopViewControllerAnimated:YES];
break;
case 3:
//popToRoot 返回至根页面
[self.navigationControllerpopToRootViewControllerAnimated:YES];
break;
case 4:
//popToView 返回至指定页面
secondVC = [[self.navigationControllerviewControllers]objectAtIndex:1];
[self.navigationControllerpopToViewController:secondVCanimated:YES];
break;
default:
break;
}
}
- IOS学习 NSNavigationController 多个子页面间相互跳转
- IOS学习 NSNavigationController 自定义:左右按钮、中间文字、背景图片
- iOS学习之创建多个子工程
- iOS应用程序间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS应用间相互跳转
- iOS 应用间相互跳转
- ios app间的相互跳转
- ios 开发不同应用间相互跳转
- 两个iOS 应用间的相互跳转
- ios总结(多页面跳转:)
- ios学习-delegate、传值、跳转页面
- IOS学习-UI_模态_页面跳转
- 【ios开发学习 - 第一课】页面跳转
- ios学习笔记:storyboard页面跳转
- 作业day08
- libsqlite3.dylib找不到
- redis内部数据结构--简单动态字符串sds
- RxJava 转换操作符groupBy
- 推荐提升 Android 性能的建议
- IOS学习 NSNavigationController 多个子页面间相互跳转
- iOS清除缓存
- oracle 跟踪事件 set event
- GridView使用的技巧
- lua获取当时时间
- VS2010下设置GDI+
- 64位CentOs6.5系统阿里云服务器源码安装MySql5
- Android进阶——安卓调用ESC/POS打印机打印
- js两种拼接字符串方法