Summary of iOS Technology
-
What is the method signature of OC in iOS?
In iOS, OC method signature includes several factors
- Method Types: (Class Method (+), Instance Method (-)
- Method name
- The number of parameters is related
However, it has nothing to do with the return value and parameter type of the method.
-
Are instance objects of Class A and Class A interacting with each other by listening for notifications of the same name?
The two will not affect each other. The parameters of push notification specify that the instance object of the class or class receives notification. Because the method type is one of the factors affecting the method signature, so when the method names of the two methods are the same, the number of parameters is the same, and the method types are different, the two methods are Different methods.
-
What's the difference between static variable declarations inside and outside the method?
- When a static variable is declared within a method, all objects calling the method share the variable.
- When a static variable is declared outside the method, the entire class shares the variable.
-
Can class extensions in. h and. m files have the same attribute or variable names?
The same class extension in two files cannot have variables with the same name, and can have attributes with the same name, but the attributes must be read-only in. h file and readable and writable in. m file.
-
When registering notifications and pushing notifications in different threads, which thread is the method of receiving notifications?
- Subthreads register listening methods, main threads push notifications, and main threads execute methods
- Subthreads register listener methods, subthreads push notifications, and subthreads push notifications execute methods
- The main thread registers the listening method, the sub-thread pushes the notification, and the sub-thread executes the method.
- The main thread registers the listening method, the main thread pushes the notification, and the main thread executes the method.
It can be seen that in which thread the notification is pushed, the method of monitoring the object of the notification is executed in which thread, and when an object registers how many times the same notification, it will not be overwritten. When a notification is pushed, the method of registration will execute how many times.
-
What's the difference between the declaration and definition formats of block code?
- When a block code is declared, it must have a variable name. In this case, the symbol ^ must be in parentheses and after the block return type, while the variable name can not be omitted after the symbol ^ or at the end of the statement, the return type can not be omitted, the parameter can be empty, but the parentheses of the parameter can not be omitted.
- When defining the block code, there is no variable name. At this time, the symbol ^ must be at the beginning of the definition statement, and then the return value type and parameters can be omitted.
-
For inline block s, they can be called directly when defined
NSString * a = ^ NSString *(NSString *string){ return string; }(@"hello world");
UIView instance object judges the value of its attribute frame before calling drawRect: method. It executes only when the width of the frame is not zero, and the frame and bounds attribute values of the instance object should not be modified in this method.
For the same device, iOS systems differentiate between different applications based on bundleID
-
When a button binds multiple events, how does the sequence of events be determined when the button is clicked?
- Click events added with code to respond in the order in which methods are added
- When a click event is added to a line in the XIB file, the signature of the comparison method (which includes':') responds from small to large according to the result.
- For a method, you can bind to multiple buttons, but when you bind to the same button multiple times, the previous binding (including the wire binding in XIB) will be overwritten, and the execution order will change.
The test code is as follows:
- (instancetype)init{ self = [super init]; if (self) { self = [[[NSBundle mainBundle]loadNibNamed:@"TestView" owner:nil options:nil]lastObject]; } [self.button addTarget:self action:@selector(btnClicked2:) forControlEvents:(UIControlEventTouchUpInside)]; [self.button addTarget:self action:@selector(btnClicked1:) forControlEvents:(UIControlEventTouchUpInside)]; [self.button addTarget:self action:@selector(btnClicked2:) forControlEvents:(UIControlEventTouchUpInside)]; return self; } - (IBAction)btnClicked3:(id)sender{ NSLog(@"%s",__FUNCTION__); } - (IBAction)btnClicked4:(id)sender{ NSLog(@"%s",__FUNCTION__); } - (IBAction)btnClicked2:(id)sender{ NSLog(@"%s",__FUNCTION__); } - (IBAction)btnClicked1:(id)sender{ NSLog(@"%s",__FUNCTION__); } - (IBAction)abtnClicked3:(id)sender{ NSLog(@"%s",__FUNCTION__); } - (IBAction)btnClicked0:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)btnClicked33:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)btnClicked33333333:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClicked4:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClickedb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClickedbb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClickedbbbbb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClicked123bb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClicked1245bbbbb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClicked123bbbbbb:(id)sender{ NSLog(@"%s",__FUNCTION__); } -(IBAction)bbtnClicked1235bbbbb:(id)sender{ NSLog(@"%s",__FUNCTION__); }
The test results are as follows:
2017-03-19 00:20:51.182 MyfirstIOSAPP[2334:165227] -[TestView abtnClicked3:] 2017-03-19 00:20:51.183 MyfirstIOSAPP[2334:165227] -[TestView bbtnClicked1235bbbbb:] 2017-03-19 00:20:51.183 MyfirstIOSAPP[2334:165227] -[TestView bbtnClicked123bb:] 2017-03-19 00:20:51.184 MyfirstIOSAPP[2334:165227] -[TestView bbtnClicked123bbbbbb:] 2017-03-19 00:20:51.184 MyfirstIOSAPP[2334:165227] -[TestView bbtnClicked1245bbbbb:] 2017-03-19 00:20:51.184 MyfirstIOSAPP[2334:165227] -[TestView bbtnClicked4:] 2017-03-19 00:20:51.184 MyfirstIOSAPP[2334:165227] -[TestView bbtnClickedb:] 2017-03-19 00:20:51.185 MyfirstIOSAPP[2334:165227] -[TestView bbtnClickedbb:] 2017-03-19 00:20:51.185 MyfirstIOSAPP[2334:165227] -[TestView bbtnClickedbbbbb:] 2017-03-19 00:20:51.185 MyfirstIOSAPP[2334:165227] -[TestView btnClicked0:] 2017-03-19 00:20:51.185 MyfirstIOSAPP[2334:165227] -[TestView btnClicked33333333:] 2017-03-19 00:20:51.186 MyfirstIOSAPP[2334:165227] -[TestView btnClicked33:] 2017-03-19 00:20:51.186 MyfirstIOSAPP[2334:165227] -[TestView btnClicked3:] 2017-03-19 00:20:51.186 MyfirstIOSAPP[2334:165227] -[TestView btnClicked4:] 2017-03-19 00:20:51.187 MyfirstIOSAPP[2334:165227] -[TestView btnClicked1:] 2017-03-19 00:20:51.189 MyfirstIOSAPP[2334:165227] -[TestView btnClicked2:]