注意: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. 用Python识别网站使用的技术

    在进行爬虫之前,一般我们都会对要爬取的网站进行识别,识别我们要爬取的网站所使用到的技术,这样才能更有利于我们爬虫工作的进行.所以在此介绍以下如何用Python去识别一个网站所使用到的技术. 环境:Py ...

  2. 如何快速查看github代码库中第一次commit的记录

    发现一个别人推荐的代码库用来学习源码, star星还不少,别人推荐从第一次commit开始阅读,于是试着去找commits的第一次 问题来了,这个代码库commits7855次,点击进入commits ...

  3. rpm体系下的linux安装httpd+mysql+…

    一.安装apache 在rpm体系下,apache称为httpd. yum install httpd 即可! 二.安装mysql yum install mysql 三.安装mysql-server ...

  4. 表达式求值(二叉树方法/C++语言描述)(一)

    使用二叉树对算数表达式(以下简称为表达式)进行求值,实质上是将表达式转换为二叉树,对其进行后序遍历,得到后缀表达式的同时可以求得表达式的值.转换和求值的过程也需要借助数据结构栈的帮助. 二叉树数据结构 ...

  5. for’ loop initial declarations are only allowed in C99 mode

    今天做南邮编程在线的编程题,编程首先计算Fibonacci数列1,1,2,3,5,8,13,21,......的前n项(n不超过40)存入一维整型数组f中,再按%12d的格式输出每项的值,每6项换一行 ...

  6. 如何在centos7上安装redis

    解压缩 tar zxvf redis-3.0.4.tar.gz 进入解压后的目录 cd redis-3.0.4 使用Make 编译源文件 make 安装 进入源文件的目录 cd src 复制 Redi ...

  7. LindAgile~大叔新宠~一个无所不能框架

    关于她 LindAgile是大叔在这两年里的新宠儿,它主推模块化,插件化,敏捷化,主要于LindAgile基础项目,LindAgile.Http项目,LindAgile.Modules项目和几个扩展模 ...

  8. python pygame--倒计时

    import pygame,sys,time,datetime class decTime(object): #将秒转化为时分秒 def __init__(self,totalTime): self. ...

  9. MySQL checkpoint深入分析

    1.日常关注点的问题 2.日志点分析 3.checkpoint:脏页刷盘的检查点 4.模糊检查点发生条件 1.master thread checkpoint 2.flush_lru_list che ...

  10. C#语言入门详解(002)

    c# 所編寫的不同應用程序 Console.WriteLine("Hello World!"); ///console textBoxShowHellow.Text = " ...