IOS tips (Continuous updates)

Source: Internet
Author: User

1. Use @ property and @ synthesize to declare a member variable. When assigning a value to it, add "self." To Call The setmember method of the member variable.

 
Directly call the member variable and assign the value to it: Member = [nsstring stringwithformat: @ "]; The setmember method is not executed.

 
Call the member variable using self and assign the value to it: Self. Member = [nsstring stringwithformat: @ "]; The setmember method is executed.


2. latency function: [nsthread sleepfortimeinterval: 3];

[Self defined mselector: @ selector (machineballaction) withobject: Nil afterdelay: 0];


3. Random Number: srandom (Time (null ));


4. # pragma mark-
 
# Pragma mark Initialization
 
They tell the xcode compiler to separate the code from the function pop-up menu at the top of the editor pane;
Note:
 
# There cannot be spaces behind the "-" Of The Pragma mark.
 
If your flag does not appear in the pop-up menu, for example, there is no separator line, please deselect "Sort listalphabetically" in "preferences..." of xcode.


5.
We send a message to the object to initiate a specific action. When the object sends some changes, it notifies us through the callback function. When a specific event occurs, the object calls the corresponding callback function to trigger the business logic.
The callback function is implemented through the so-called delegation.

How to Use delegate:

@ Property (assign) <ID> xxxdelegate delegate;

The correct method is to use the assign attribute instead of the retain.

The reason for using assign for objects such as delegate instead of retain is to prevent loop retain loop ).
For specific reasons, move to: http://www.cnblogs.com/kimimaro/archive/2011/09/05/2167576.html


6. Programming habits: when defining bool type values, @ property (nonatomic, Getter = issoundon) bool soundon;


7. manually create a memory to automatically release the pool:

NSAID utoreleasepool * Pool = [[NSAID utoreleasepoolalloc] init];

// Todo

// When an autorelese message is sent to an object, the object is added to the memory release pool that you have manually created. Call [pool release] at the end of this method to release all objects added to the memory pool.

[Pool release];

// If the retaincount of an object is not 0 after the Auto Release pool calls the release method, the object will remain available.

8. Any basic data type (including char data type) can be used to create an object based on the data type by using the nsnumber class.

Nsnumber * mynumber, * floatnubmer; // long value mynumber = [nsnumber numberwithlong: 0 xabcdef]; nslog (@ "% lx", [mynumber longvalue]); // output: abcdef // char value mynumber = [nsnumber numberwithchar: 'X']; nslog (@ "% C", [mynumber charvalue]); // output: X // float value floatnubmer = [nsnumber numberwithfloat: 100.00]; nslog (@ "% G", [floatnubmer floatvalue]); // output: 100

9. when an object is added to the array or dictionary in the form of addobject or initialization, The retaincount of this object will be + 1.

When an object is removed from array and dictionary in the form of remover, The retaincount object is-1.

When copy and mutablecopy are used to generate an array copy, the keep count of each element in the array is + 1.

10. Exception: exc_bad_access.

The referenced object has been released, that is, "Devil reference ". Similar to vs's "The referenced object is not applied to the instance of the object.

11. Questions about updating uitableview data:

The sqlite3 lightweight database is used to store data. Through debugging, it is found that the data in the database has been updated, but the uitableview is not updated.

Solution: descrimselecdomainmainthread: @ selector (reloaddata) withobject: Nil waituntildone: Yes

However, datasource does not have data and data needs to be reloaded.


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.