在iOS开发中关于正向传值的问题

两个输入框和一个按钮

    _TextFiled  = [[UITextField alloc]init];
	_TextFiled.frame = CGRectMake(0, 100, 320, 50);
    _TextFiled.textColor = [UIColor redColor];
    _TextFiled.borderStyle = UITextBorderStyleRoundedRect;
    _TextFiled.font = [UIFont boldSystemFontOfSize:20];
    _TextFiled.delegate = self;
    _TextFiled.tag = 1000;
    [self.view addSubview:_TextFiled];
    
    _TextFiled1 = [[UITextField alloc]init];
    _TextFiled1.frame = CGRectMake(0, 300, 320, 50);
    _TextFiled1.textColor = [UIColor redColor];
    _TextFiled1.borderStyle = UITextBorderStyleRoundedRect;
    _TextFiled1.font = [UIFont boldSystemFontOfSize:20];
    _TextFiled1.delegate = self;
    _TextFiled1.secureTextEntry = YES;
    _TextFiled1.tag = 2000;
    [self.view addSubview:_TextFiled1];
    
    _button = [UIButton buttonWithType:UIButtonTypeCustom];
    _button.frame = CGRectMake(320 / 2, 360, 100, 50);
    UIImage * image_button = [UIImage imageNamed:@"9.gif"];
    [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [_button setImage:image_button forState:UIControlStateNormal];
    
    [_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:_button];

传值的方法

-(void)buttonAction{
    
    //正向传值
    UITextField * textField1 = (UITextField *)[self.view viewWithTag:1000];
    UITextField * textField2 = (UITextField *)[self.view viewWithTag:2000];
    
    ViewController_text * text = [[ViewController_text alloc]init];
    text.text1 = textField1.text;
    text.text2 = textField2.text;
    
    //切换到下一界面
    [self presentViewController:text animated:YES completion:nil];

}

在下一个界面中得到值:

UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 200, 310, 50)];
    label.textAlignment = NSTextAlignmentLeft;
   //从上一个界面传下来的值
    label.text = [NSString stringWithFormat:@"Text1:%@ ----- Text2:%@", _text1,_text2];
    label.textColor = [UIColor redColor];
    [label setFont:[UIFont boldSystemFontOfSize:20]];
    label.backgroundColor = [UIColor grayColor];
    [self.view addSubview:label];




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值