注意:ViewController.m文件
// 在第一个页面中,创建一个简单的登录页面,并且添加两个属性
1 #import "ViewController.h"
#import "HomeViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *headerImage;
  // 属性一
@property (weak, nonatomic) IBOutlet UITextField *username;
  // 属性二
@property (weak, nonatomic) IBOutlet UITextField *password;
  // 点击事件
7 - (IBAction)LoginButtonOnClick:(UIButton *)sender; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
} // 此方法用于切换键盘的控制器
- (BOOL)textFieldShouldReturn:(UITextField *)textField{ //如果是第一个文本框 取消第一个 并且给第二个
if (textField == self.username) {
[textField resignFirstResponder];
[self.password becomeFirstResponder];
} //如果是第二个 退出响应
if (textField == self.password) {
[textField resignFirstResponder];
}
return YES;
} // 点击空白部分回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
} - (IBAction)LoginButtonOnClick:(UIButton *)sender {
//新建视图
HomeViewController *hvcl = [[HomeViewController alloc]init];
//此处新建下一个页面,用属性的点语法,将当前获得文本的赋值给第二个页面里面的属性 (注意接受类型)
hvcl.userName = self.username.text;
hvcl.passWord = self.password.text;
    //推送到下一页的动画
[self presentViewController:hvcl animated:YES completion:nil];
hvcl.modalTransitionStyle = UIModalTransitionStyleCoverVertical; }
@end
注意:HomeViewController.h 文件  

在HomeViewController.h 里面我们新建了 两个外部可以访问的属性代码:当我们新建HomeViewController 的对象时候便可以给他里面属性赋值,这样我们便达到了简单的第一个页面传值到第二个页面

#import <UIKit/UIKit.h>

  @interface HomeViewController : UIViewController

  //属性一

  @property (nonatomic,copy)NSString *userName;

  //属性二

  @property (nonatomic,copy)NSString *passWord;

  @end

》  

注意:这是HomeViewController.m文件
#import "HomeViewController.h"
@interface HomeViewController ()
- (IBAction)bankButtonOnClick:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;
@end @implementation HomeViewController - (void)viewDidLoad {
[super viewDidLoad]; // 字符串拼接
_welcomeLabel.text = [NSString stringWithFormat:@"亲爱的%@,欢迎来到%@章节",self.userName,self.passWord];
}
//
- (IBAction)bankButtonOnClick:(UIButton *)sender {
//销毁当前视图 返回第一视图
[self dismissViewControllerAnimated:YES completion:nil]; }
@end

完整代码:

#import "ViewController.h"
#import "HomeViewController.h"
//遵守协议
@interface ViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *headerImage;
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (nonatomic ,strong)UIActivityIndicatorView *activityIndView;
- (IBAction)LoginButtonOnClick:(UIButton *)sender; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 设置控制器作为文本框的代理代理
self.username.delegate = self;
self.password.delegate = self;
self.headerImage.layer.cornerRadius = ;
self.headerImage.layer.masksToBounds = YES;
NSLog(@"%f %f", _headerImage.frame.size.width, _headerImage.frame.size.height); #pragma make__活动指示器
// 活动指示器的样式
_activityIndView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
//位置
_activityIndView.bounds = CGRectMake(, , , );
_activityIndView.center = CGPointMake(self.view.center.x, self.view.center.y); //动画停止随及隐藏
_activityIndView.hidesWhenStopped = YES; [self.view addSubview:_activityIndView];
} // 搜索这个方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{ //如果是第一个文本框 取消第一个 并且给第二个
if (textField == self.username) {
[textField resignFirstResponder];
[self.password becomeFirstResponder];
} //如果是第二个 退出响应
if (textField == self.password) {
[textField resignFirstResponder];
}
return YES;
} // 点击空白部分回收键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
} - (IBAction)LoginButtonOnClick:(UIButton *)sender { //点击登录按钮 判断文本框类容。
[_activityIndView startAnimating];
//新建视图
HomeViewController *hvcl = [[HomeViewController alloc]init];
//辅助
hvcl.userName = self.username.text;
hvcl.passWord = self.password.text;
[self presentViewController:hvcl animated:YES completion:nil];
hvcl.modalTransitionStyle = UIModalTransitionStyleCoverVertical; }
@end

ViewController.h

#import <UIKit/UIKit.h>

@interface HomeViewController : UIViewController

@property (nonatomic,copy)NSString *userName;
@property (nonatomic,copy)NSString *passWord; @end

HomeViewController.h

#import "HomeViewController.h"

@interface HomeViewController ()

- (IBAction)bankButtonOnClick:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *welcomeLabel;

@end

@implementation HomeViewController

- (void)viewDidLoad {
[super viewDidLoad]; // 字符串拼接
_welcomeLabel.text = [NSString stringWithFormat:@"亲爱的%@,欢迎来到%@章节",self.userName,self.passWord];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
} - (IBAction)bankButtonOnClick:(UIButton *)sender { //销毁当前视图 返回第一视图
[self dismissViewControllerAnimated:YES completion:nil]; }
@end

HomeViewController.m

ios初体验< 运用属性传值,登录>的更多相关文章

  1. ios 初体验<真机调试>

    1.很多小伙伴,初学ios后面,都想迫不及待的连接上真机,在真机上调试,本人今天花了许久时间,在网上查了许多资料,一直出现了个问题导致我没法真机调试, 问题一:Your session has exp ...

  2. ios 初体验<UILabel控件>

    创建控件: UILabel *label = [[UILabel alloc]init]; //设置控件大小 label.frame = CGRectMake(50,100,300,40);//分别为 ...

  3. ios 初体验<窗口的创建>

    1. 创建工程,这步很简单,百度下即可,在info.plist 里面 去掉 Main 的 ,便于新手练习ios,创建ios工程后,在AppDelegate.m,里面的方法application 加上几 ...

  4. beego 初体验 - 参数与传值

    beego 支持 restful 风格的 url 传值分为路由传值和表单传值,表单传值可以绑定实体对象 1行 :id/:date 就是路由传值 2.3行是表单传值的路由配置 后台如何接收? 这是con ...

  5. ios 初体验< UISegmentedControl 分段控件>

     小知识:  数组快速创建 @[@"",@"",@"",@"".......],字典快速创建方法:@{@"&q ...

  6. ios 初体验<页面切换>

    本章类容:介绍如何新建一个页面,打开另一个页面 1.在前面中,在工程Appdelegate.m 里面程序第一个走的方法,新建一个窗口,视图,控制器,可视化等, 2.然后在ViewController. ...

  7. ios 初体验<UIButton 控件>

    1.创建UIButton 跟其他方式不同,不是直接alloc,init 创建 用工厂化方式创建 UIButton *sureBtn = [UIButton buttonWithType:UIButto ...

  8. Xamarin.iOS开发初体验

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKwAAAA+CAIAAAA5/WfHAAAJrklEQVR4nO2c/VdTRxrH+wfdU84pW0

  9. iOS AR技术初体验,使用EasyAR示例程序的小白指南

    QQ前两天的传递火炬,是我第一次直接接触到AR.(虽然之前听同事说过,因为他喜欢玩游戏,PS.3DS等等都玩过,这个技术最开始就是从这里出现的).所以感觉很有趣,就想自己也试着搞一下玩玩...下面是我 ...

随机推荐

  1. mysql 5.7 root密码重置(centos 7)

    mysql5.7版本之后,与mariadb不同,在安装之后,在启动之时,会进行自动随机密码的设定,所以在systemctl start mysqld之后,会出现mysql -uroot -p无法登陆的 ...

  2. [补档][HNOI 2008]GT考试

    [HNOI 2008]GT考试 题目 阿申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9),他不希望准考证号上出现不吉利的数字. 他的不吉利数学A1A2... ...

  3. 用vector实现dijkstra

    #include <stdio.h> #include <string.h> #include <string> #include <vector> # ...

  4. 用u盘启动计算机

    上次只是做好了u盘启动盘,但是并没有说怎么安装系统.接下来说一下怎么装系统.链接:怎么把系统装进u盘(ultraiso) 电脑经常要用到u盘启动.设置u盘启动在bios设置里面进行设置.下面就来讲解一 ...

  5. zabbix_server----邮箱报警

    zabbix邮件报警部署!!!!!!!!!!!!!!! Zabbix监控服务端.客户端都已经部署完成,被监控主机已经添加,Zabiix监控运行正常,通过查看Zabbix监控服务器,可以了解服务器的运行 ...

  6. NYOJ-63 小猴子下落(二叉树及优化算法详解)

      小猴子下落 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 有一颗二叉树,最大深度为D,且所有叶子的深度都相同.所有结点从左到右从上到下的编号为1,2,3,··· ...

  7. 什么是IAT重定向

    例壳:telock 0.98 仅允许非商业转载,转载请注明出处

  8. hadoop生态圈列式存储系统--kudu

    介绍 Kudu 是一个针对 Apache Hadoop 平台而开发的列式存储管理器.Kudu 共享 Hadoop 生态系统应用的常见技术特性: 它在 commodity hardware(商品硬件)上 ...

  9. Windows下WebStorm使用SVN(转)

    安装了WebStorm之后,想配置svn,结果在file->settings->Version Contorl->subversion->with conmand line c ...

  10. Mybatis(二)

    1 Mybatis映射文件--增删改查 POJO类 package cn.demo1; import org.apache.ibatis.type.Alias; /** * 描述:POJO */ @A ...