如題。。。小白學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
NSString *combinedWord= [firstText.text stringByAppendingString:secondText.text];
或
NSString *combinedWord= [NSString stringWithFormat:@"%@%@",firstText.text,secondText.text];
stringByAppendingString
用來拼接一個字串stringWithFormat