Zero-based Objective-c and Xcode-based ios development study notes No.1 Create a login interface

Synchronous learning with Android development based on Android Studio,
starting with zero foundation,
I hope I can update every week

1.Objective-C 拼接字符串
Objective-C doesn’t use ‘+’ operator for concatenation.
This way should work:

NSString *concat = [NSString stringWithFormat: @"%@%@", TextField1.text, TextField2.text];

or

NSString *concat = [TextField1.text stringByAppendingString:TextField2.text];

Specific examples:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"登陆成功"
       message:[NSString stringWithFormat: @"%@%@", @"你刚才输入的是", message]
preferredStyle:UIAlertControllerStyleAlert];

among them:

NSString *username = [tfUserName text];
NSString *pwd = [tfPWD text];
NSString *message = [NSString stringWithFormat:@"用户名:%@ 密码:%@", username, pwd ];

NSString *concat = [NSString stringWithFormat: @"%@%@", @"你刚才输入的是", message];

2. Objective-C uses two files to describe a class

The declaration file of the .h class
uses the keywords @interface and @end

The implementation file of the .m class
uses the keywords @implementation and @end

Objective-c is single inheritance

NSObject is the root class of all classes

-#import is better than #include to prevent duplicate inclusion

In general, once you use @property to declare a property, the compiler will automatically generate a pair of access methods for the property. The access methods generated by the compiler comply with the following naming conventions:

1) The method used to access the attribute value, the getter method, whose name is the same as the name of the attribute;

2) The method used to set the attribute value, the setter method, whose name starts with "set", followed by the attribute name, and the first letter of the attribute name is capitalized;

The dot syntax is just a convenient way to access method calls. When you use dot syntax, properties are still accessed or changed through getter or setter methods.

Message: An object can send and receive messages, and an object can send a message to another object by calling a method of the object. This is the objective-C term, which is a function call.

[self presentViewController:alertController animated:YES completion:nil]; //对象给自己发送消息

Objective_C uses id instead of void*

atomic 和 nonatomic

The getter/setter methods automatically generated by the nonatomic system will not be locked

'The lock only guarantees the thread safety of the getter and setter access methods'

Xcode articles

AppDelegate.h, AppDelegate.m: application delegate.
ViewController.h, ViewController.m: the controller of the interface.
main.storyboard storyboard, used to design and organize the APP interface, you can also use pure code or Xib to design the interface, and you can even mix the three.
The product directory is the final generated APP

segue interface jump

Simple login interface and button event implementation: `
Declare methods and properties in ViewController.h:

- (IBAction) userLogin:(id)obj;
- (IBAction) userRegisiter:(id)obj;
- @property (nonatomic, retain) IBOutlet UITextField *tfUserName;
- @property (nonatomic, retain) IBOutlet UITextField *tfPWD;

Implemented in ViewController.m:


- (IBAction)userRegisiter:(id)obj {
    
     //用户点击注册按钮
    
    //Objective_C使用id代替void*
    
    NSString *username = [tfUserName text];
    NSString *pwd = [tfPWD text];
    NSString *message = [NSString stringWithFormat:@"用户名:%@ 密码:%@", username, pwd ];
    
    //create UIAlertController
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"注册成功"
           message:[NSString stringWithFormat: @"%@%@", @"你申请的账户是:\n", message]
    preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
    
    
           NSLog(@"OK Action");
       }];
       UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    
    
           NSLog(@"Cancel Action");
       }];

       [alertController addAction:okAction];           // A
       [alertController addAction:cancelAction];       // B
       
       [self presentViewController:alertController animated:YES completion:nil]; //对象给自己发送消息
        //方法的参数传递采用中缀符的形式,利用“:”分割参数名和被传递参数
        //YES和NO相当于True和False
        //nil相当于null
        
}

effect:
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_56336619/article/details/115033495