Basic knowledge of IOS development

Source: Internet
Author: User

1. Why do I need to set it to nil after a variable is release?

After a variable is release, the memory to which the variable points is released, but the variable itself remains unchanged and still points to the original memory address. If this variable is accessed after it is released, or it is repeatedly release, the application will crash. If it is set to nil, this variable points to 0 × 00, which ensures that the program will not be able to access the original memory address in the future, and there is no problem with the nil release.

2. What is the difference between adding self before using class members?

Without self, the get set Method of the member is called. After self is added, the get set Method of the member is actually called.

Example:

//. H

@ Property (nonatomic, retain) NSString * name

//. M

Name = @ "bang" // No retain will be released at any time

NSString * str = self. name // NSString * str = [self name];

Self. name = @ "bang" // equals to [self setName: @ "bang"]; then the string is retained in the set method.

3. Memory leakage

You can use the xcode compilation tool Product-Analyze to check possible leakage points within the function block range (some possible errors will be prompted for the external band ).

The leak search method monitored by leaks is to track the variables that appear in the Code prompts. This variable is often leaked outside the prompt call stack. If it cannot be found, the final method is to rewrite the retain and release methods of this variable. debug, from the call stack, shows who retain it and no release.

Note that the variables generated with CFXXCreate (for example, CFArrayCreate) must be released with CFRelease.

4. Data Storage

If you do not need to search, you can serialize a data object and save it to sqlite. During retrieval, the data object is deserialized for use. Serialization requires the data class to implement the NSCoding protocol and encodeWithCoder and initWithCoder methods. If there are multiple data objects, you can write a base class to implement these two methods, in this case, we use reflection to enumerate all our variables to encode and decode. Once and for all, we can find them online.

5. Hide the UINavigationController header and tail

When you use NavigationController to manage push and pop of a view, you must set whether to display NavigationBar and ToolBar based on different view settings, as a result, if the NavigationBar and ToolBar are not displayed, it is displayed on viewWillAppear. Don't laugh at me. I didn't understand the whole process well and never found out.

-(Void) viewWillAppear :( BOOL) animated {

[Super viewWillAppear: animated];

[Self. navigationController setToolbarHidden: NO];

[Self. navigationController setNavigationBarHidden: NO];

}

6. UITableView cursor Rendering

The tableView mechanism is probably to set the total number of rows first. When a row is rolled into the view range, a function is called back to retrieve the view for display. This row will continue to be called back when the view is rolled back. This mechanism means that no matter how much data in your table is, you can put all the data into the table without paging, because you do not need to retrieve all the data at once, you only need to retrieve the corresponding data based on the cursor when you need to display it.

This may be a natural way for APP components, but the data and elements on the web page must be loaded into the memory at a time. After a long time, the web did not expect such an implementation mechanism at first, as a result, we have taken many detours.

7. UIWebView rendering range

UIWebView does not determine the rendering range for each time based on the visible range, but is determined based on the frame size of its own control.

I tried to embed webview in tableview. In order to make the webview and tableview scroll together, set the webview size to the content size in webview, so that webview does not display the scroll bar, this can be rolled along with the scroll bar of tableview. The consequence of this is that every time a webview renders the entire page at a time, the memory usage is very poor, and when the webview is zoomed in and out, the rendering of the whole page is more difficult, performance that is intolerable. The solution is to set the height of webview to the height of the iphone of the whole screen, which limits the visible rendering range of webview each time and improves the performance. The problem is that you cannot scroll with tableview, but you can optimize the experience in other ways. Recently, ZAKER of the new version is also doing the same.

Http://www.cnblogs.com/roucheng/

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.