Xcode Day 1: Append String & Text Properties
result out put
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
// // ViewController.m // MyApplication2 // // Created by Local Admin on 7/8/56 BE. // Copyright (c) 2556 Local Admin. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize myLebel; @synthesize myText; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)myButton:(id)sender { NSString * ss=@"hello "; ss=[ss stringByAppendingString:myText.text]; myLebel.text=ss; } @end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// // ViewController.h // MyApplication2 // // Created by Local Admin on 7/8/56 BE. // Copyright (c) 2556 Local Admin. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *myText; @property (weak, nonatomic) IBOutlet UILabel *myLebel; - (IBAction)myButton:(id)sender; @end |
ถ้าต้องการตรวจสอบ length ของ textbox ให้ใช้ตามนี้
1 2 3 4 5 |
NSString * s=myText.text; if([s length]==0) { } |
อะไรที่เป็น pointer จะใช้ วรรค สังเกตุถ้า * จะมีวรรคตรง s length
Recent Comments