Heim > Fragen und Antworten > Hauptteil
如题。。。小白学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
巴扎黑2017-04-22 09:02:31
NSString *combinedWord= [firstText.text stringByAppendingString:secondText.text];
或者
NSString *combinedWord= [NSString stringWithFormat:@"%@%@",firstText.text,secondText.text];
PHP中文网2017-04-22 09:02:31
- (IBAction)myButtonPressed:(id)sender {
self.combinedWord.text = [self.secondText.text stringByAppendingString:self.firstText.text];
}
stringByAppendingString
用来拼接一个字符串