在iOS開發中關於正向傳值的問題

來源:互聯網
上載者:User

兩個輸入框和一個按鈕

    _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];




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.