Heim  >  Fragen und Antworten  >  Hauptteil

objective-c - 想做一个可以讲textfield中的内容合并为一个字符串的功能

如题。。。小白学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

迷茫迷茫2759 Tage vor486

Antworte allen(3)Ich werde antworten

  • 巴扎黑

    巴扎黑2017-04-22 09:02:31

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

    或者

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

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-22 09:02:31

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

    stringByAppendingString用来拼接一个字符串

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-04-22 09:02:31

    stringWithFormat

    Antwort
    0
  • StornierenAntwort