Basic knowledge of IOS

Source: Internet
Author: User

1.Why do we need to set the value 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. This variable points to 0 × 00 after being set to nil, which can be ensuredProgramIn the future, the original memory address will not be accessed, and the NIL release will not be any problem.

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 itCodeThe variable that appears in the prompt. 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.Uinavigationcontroller head/end display hidden

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.

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.