IOS tips (Continuous updates) and ios tips

Source: Internet
Author: User

IOS tips (Continuous updates) and ios tips

 

1. How to set the font size of the Button title through code

Set Button. titleLabel. font = [UIFont systemFontOfSize: <# (CGFloat) #>];

 

2. Get the current time

    NSDate *timeDate=[NSDate date];        NSDateFormatter * dateformatter=[[NSDateFormatter alloc] init];        [dateformatter setDateFormat:@"YYYYMMddHHmmsssss"];        NSString *locationString=[dateformatter stringFromDate:timeDate];

 

3. Determine whether a string is a NULL Character

- (BOOL) isBlankString:(NSString *)string {    if (string == nil || string == NULL) {        return YES;    }    if ([string isKindOfClass:[NSNull class]]) {        return YES;    }    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {        return YES;    }    return NO;}

 

4. tableView Optimization

// Refresh the entire table [_ tableView reloadData]; // refresh the current row [_ tableView reloadRowsAtIndexPaths: @ [indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];

 

5. Baidu map custom pin pictures

-(BMKAnnotationView *) mapView :( BMKMapView *) view viewForAnnotation :( id <BMKAnnotation>) annotation {// generate reuse identifier static NSString * AnnotationViewID = @ "AnnotationViewID "; // check whether there are reused cache BMKAnnotationView * annotationView = [view dequeueReusableAnnotationViewWithIdentifier: AnnotationViewID]; (BMKPinAnnotationView *) annotationView ). pinColor = BMKPinAnnotationColorGreen; annotationView. image = [UIImage imageNamed: @ "XXX.png"];}

 

6. screen size required for iOS APP mounting

640*960, 640*1136, 750*1334, 1242*2208

 

7. iOS APP Icon size

58*58, 80*80, 120*120, 180*180

 

8,

Apple account application: This is the application method: accept/

 

9. Disable the timer.

[_ MyTimer invalidate];

_ MyTimer = nil;

 

10. First Response to keyboard release

-(BOOL) textFieldShouldReturn :( UITextField *) textField {

[TextField resignFirstResponder];

Return YES;

}

 

11. When you click UITableViewCell, there is no click effect,

Write in cellForRowAtIndexPath: Method

Cell. selectionStyle = UITableViewCellSelectionStyleNone;

 

12. The object returned by NSJSONSerialization depends on the outermost layer. If it is {}, It is the dictionary, and [] It is the array.

 

13. Only the portrait screen is supported. You can modify the info. plist file. Find "Supported interface orientations" and set the item to Portrait. This setting is global.

 

14. iOS development

First build the framework, then draw the interface, write function, write interface, debugging, write adaptation

IOS development document flowchart UI framework interface function adaptation test changes
Basic C language and swift language for iOS beginners
Intermediate iOS development engineer iOS Project Development + UI + animation Layer

 

15. The procedure for executing each method in the life cycle of ViewController is as follows:

Init-> loadView-> viewDidLoad-> viewWillApper-> viewDidApper-> viewWillDisapper-> viewDidDisapper-> viewWillUnload-> viewDidUnload-> dealloc

 

16. GCD

1) The Main queue running in the Main thread is obtained through dispatch_get_main_queue.
2) The global dispatch queue of the parallel queue is obtained through dispatch_get_global_queue. The system creates three dispatch queue with different priorities. The execution sequence of the parallel queue is the same as that of the queue.
3) serial queue serial queues is generally used for sequential synchronous access. You can create any number of serial queues, and each serial queue is concurrent.

17. In the Xcode project, we often encounter memory leaks and program crashes due to empty data (the data transmitted by the server is parsed to something like JsonKit, this has been pitted many times in the past, so it is necessary to encapsulate a non-empty processing class. Due to limited capabilities, you can view some online materials and think of recursive processing.

Solution: a foreigner has already had an empty processing artifact in Githud: https://github.com/nicklockwood/nullsafe. you only need to add this Category to the project, so you can have no worries. I do not know much about the code in it, so everyone will study it by themselves.

 

18. Read plist files

NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "provinces. plist" ofType: nil];

NSArray * arr = [NSArray arrayWithContentsOfFile: filePath];

// Load plist data // A NSBundle object corresponds to a resource package (images, audio, video, plis, and other files) // NSBundle function: used to access the files in the corresponding resource package, resources that can be used to obtain the full path of the file // resources added to the project will be added to the main resource package // [NSBundle mainBundle] associated with the project's main resource package NSBundle * bundle = [NSBundle mainBundle]; // use mainBundle to obtain the full path of the plist file in the primary resource package NSString * file = [bundle pathForResource: @ "shops" ofType: @ "plist"]; // NSString * file = [bundle pathForResource: @ "shops. plist "ofType: nil]; // All parameters named File pass the full path shopsArray = [NSArray arrayWithContentsOfFile: file];

19. Lazy loading: Load again when used, and load only once

(1). Lazy Loading

Lazy loading, also known as delayed loading, is loaded only when needed (low efficiency and low memory usage ). The so-called lazy loading writes the get method.

NOTE: If it is a lazy load, you must first determine whether there is already, if not, then instantiate it.

(2). Benefits of using lazy loading:

Benefit 1: you do not have to write all the code for creating an object in the viewDidLoad method. The code is more readable.

Benefit 2: The getter method of each control is responsible for instantiating each other. The code is highly independent and loosely coupled.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.