2015-12-16--UI7_页面跳转 - 传值
//
// AppDelegate.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (retain, nonatomic) UIWindow *window;
@end
//
// AppDelegate.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "AppDelegate.h"
import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
} - (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];RootViewController *rootVC = [[RootViewController alloc]init];
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:rootVC];
self.window.rootViewController = navi;
[navi release];
[rootVC release];[_window release];
return YES;
} - (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
} - (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
} - (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
} - (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
//
// RootViewController.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
@end
//
// RootViewController.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "RootViewController.h"
import "SecondViewController.h"
@interface RootViewController ()
@property (nonatomic, retain)UITextField *textField;
@end
@implementation RootViewController
(void)dealloc
{[_textField release]; [super dealloc];
}
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; // // 要求 // 1.创建工程 设置导航为根视图 rootVC为导航的根视图 // 2.rootVC 中创建一个textField(属性/tag)和一个button(实现点击 简单NSLog) // 3.创建SecondVC类
// UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"动画", @"游戏"]];
// seg.frame = CGRectMake(100, 100, 100, 30);
// seg.selectedSegmentIndex = 0;
// self.navigationItem.titleView = seg;
// [seg release];
// 标题
self.title = @"首页";
// textField
_textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];
_textField.backgroundColor = [UIColor redColor];
_textField.placeholder = @"sda";
[self.view addSubview:_textField];
[_textField release];
// 按钮
UIButton *bt = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 50, 30)];
bt.backgroundColor = [UIColor yellowColor];
[bt addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bt];
[bt release];
}
-(void)button
{
NSLog(@"diandian");
// push页面
// 1.创建第二页对象
SecondViewController *secVC = [[SecondViewController alloc]init];
warning 2. 给第二页面的对象属性赋值
secVC.str = self.textField.text;
// 2.push操作 导航控制页面的push
[self.navigationController pushViewController:secVC animated:YES];
[secVC release];
if 0
// 模态
// 1.创建对象
SecondViewController *secVC = [[SecondViewController alloc]init];
// 2.模态
[self presentViewController:secVC animated:YES completion:^{
//
}];
endif
}
(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.
}
/*
pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.
}
*/
@end
//
// SecondViewController.h
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController
warning 界面之间通信 属性传值(1->2)
warning 1.在第二页的.h文件 写一个对应类型的属性 用于接收数据
@property (nonatomic, copy)NSString *str;
@end
//
// SecondViewController.m
// UI7_页面跳转
//
// Created by YIem on 15/12/15.
// Copyright (c) 2015年 www.yiem.net YIem博客. All rights reserved.
//
import "SecondViewController.h"
import "RootViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor];
warning 3.使用属性
// 设置标题
self.title = self.str;
//创建按钮
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
button.backgroundColor = [UIColor redColor];
[button addTarget:self action:@selector(button) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[button release];
}
(void)button
{// 返回上一页 [self.navigationController popViewControllerAnimated:YES]; // 直接返回首页
// [self.navigationController popToRootViewControllerAnimated:YES];
// 返回到指定页面 // viewControllers VC数组 保存所有的导航管理的控制器
// [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES];
}
(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.
}
/*
pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.
}
*/
@end
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »