objective-c - 想做一个可以讲textfield中的内容合并为一个字符串的功能
迷茫
迷茫 2017-04-22 09:00:31
0
3
505

如题。。。小白学IPHONE 开发,

linke了两个text fild一个button,一个label,想要实现讲两个text field中输入的字符串合并为一个,点一下button就会显示在lable中

附上代码:

@interface HWViewController ()
@property (strong, nonatomic) IBOutlet UILabel *combinedWord;
@property (strong, nonatomic) IBOutlet UITextField *secondText;
@property (strong, nonatomic) IBOutlet UITextField *firstText;
@property (strong, nonatomic) IBOutlet UIButton *combineButton;


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.combinedWord.text=@"Wating...";

}
- (IBAction)myButtonPressed:(id)sender {
    NSString *combinedWord= textfiled1+textfield2

求高手回答,想自己做一个project来学习,看了document感觉还是不太会,Q

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
巴扎黑

NSString *combinedWord= [firstText.text stringByAppendingString:secondText.text];

or

NSString *combinedWord= [NSString stringWithFormat:@"%@%@",firstText.text,secondText.text];

Ty80
- (IBAction)myButtonPressed:(id)sender {
    self.combinedWord.text = [self.secondText.text stringByAppendingString:self.firstText.text];
}

stringByAppendingStringUsed to concatenate a string

巴扎黑

stringWithFormat

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template