iOS Development--full project in combat OC & 11th day of best sister

Source: Internet
Author: User

The 11th day of Miss Scarlett's sister

One: There is no ID in the model attributeAdd a property ID to the model, set the name substitution
/** ID *
/
@property (nonatomiccopy) nsstring *id; Replace:+ (Nsdictionary*)Replacedkeyfrompropertyname
{
Return@{@ "ID":@ "id" };
}second: The wrong array is used as a dictionary.(In fact, there is no data, such as refresh data is no longer, or directly 0) through the Stack positioning error last page: There is no next page of data, but also send a request to the server, the server reception returned empty data, the solution, When the last page is finished and the load is complete, stop the request to end the refresh: When the request succeeds: (or set hidden equals Yes) Note: Better to do more than equals (users may delete the corresponding post when we refresh)Three: There is a property in the parent class with different values in different subclasses
    • 1: Determine the corresponding attribute in the parent class for different subclass settings (not recommended, because the parent class needs to have subclasses)
2: Create an external property (type) that displays different types according to the values set by the subclass to create all the child controllers (subclasses) passing the corresponding type in the
    • 3: If in the way above, because there is no code for the subclass, so there is no need for subclasses, direct food using the parent class to create all subclasses, only need to set the corresponding type (disadvantage: Subclass no extensibility)
    • 4: Use subclasses to implement your own stuff inside subclasses (cons: Changing attributes, calling Super's order)
    • 5. Override the Getter method of the parent class's corresponding property (disadvantage: May be assigned outside)
    • 6. Set the property's ReadOnly, overriding the Getter method of the parent class's corresponding property (disadvantage: Generate extra underscore type property, waste resources) ß
    • 7. Best Practices:
To turn a property into a getter method: The parent class has something that only wants the subclass to do, this time using the override method to implement this method in the parent class, eliminate the warning-(Xnmtopictype) type {return 0;} subclasses are simple to use, just rewrite the Getter methodfour: About inheritance, classification, outreach
    • The difference between inheritance and classification, expansion
1. Inheriting inherit inheritance is an attribute of any object-oriented language. Subclasses can inherit the properties and methods of the parent class. There are two cases in which inheritance must be used, but not categorized.
    • A. When the method that needs to be extended has the same name as the original method, and you need to call the parent class with the same name method, you need to inherit. If classification is used at this time, the implementation of the classification method overrides the implementation of the original method and does not access the original method.
    • B. When the property needs to be extended.
2. Category: This is the OC-specific attribute, you can extend the class without changing the class name and the implementation of the original class. In the following cases, it is best to use categories:
    • A. Extend for some classes of the system. For example, NSString, Nsarray, NSNumber, etc., the system itself does not advocate the use of inheritance to extend the method, because these classes within the implementation of the inheritance is limited, so it is best to use the classification of the way to expand.
    • B. Categories support developers to build their own classes, grouping related methods into separate files, for large and complex classes, to improve maintainability and readability, and to simplify the management of individual source files.
Category extensions are also categorized and Extension. When you create a file in Xcode, the two files are separated. The difference between category and extension:
    • 1. Extension is an anonymous category.
    • 2. The method defined by Extension must be implemented in the implement of the class, and the category is not forced.
    • 3. Extension can define attributes, and category cannot define attributes.
Five: There's something only a subclass can accessVI: Set Fengexian for CelThe first setting in cell split line is full Screen 1: Each cell bottom plus a height of 1 uiview (the worst, but uiview too much, poor performance) 2: All the cell height up (setframe) 3: Directly requires the artist to do a mark of the picture, Set the cell background picture Advanced Article Seven: Popup Text Action menu, copy, paste, cut, select all
    • 1: Ask the artist to show this picture, listen to the area of the click, do the corresponding things
Cons: More rigid
    • 2: Customize the control, listen for text long press the popup control menu, listen to the click of the control's child control (button)
Here you can use a large background image or you can add a background picture for each button or set a picture disadvantage: you need to calculate the location and decide where to add it
    • 3: Long Press event Menu
here is the introduction of the next Uimenucontroller, this is the controller is the entry of such events, we add new features through UIMenuItem.
1  2 3 UIMenuItem *mapitem = [[UIMenuItem alloc] Initwithtitle:@ " share to Weibo "  action:@ Selector (blogaction:)]; 4 5 Uimenucontroller *menucontroller = [Uimenucontroller Sharedmenucontroller]; 6 7 [Menucontroller Setmenuitems:[nsarray Arraywithobject:mapitem];

Here I have added a feature to share to Weibo, when the event is triggered, execute Blogaction: method.

here, We probably also need to use this method with:

 1 -(BOOL) Canperformaction: (SEL) Action Withsender: (id   2  3  4  if  (Action = = @selector (blogaction:) | | action == @selector (copy:)  5   { 6  return   YES;  7   8  return   NO;  9 } 
Eight: Method wiring error or not deletedNine: Specify the corresponding view10: Or select the cell line number11: Point syntax requires a method of declaration: If you do not write, there is no way to prompt12: Menucontroller can only have one instanceFIX: Create with simple interest 13: The text is the back of the blue loaded up, so the label will be added before the back of the blockWorkaround: Set the settings that you added later to set the background for clearcolor implementation of the text in the button to set the state: Note: Cell Click Causes the selection, the system will be customized to let all the controls inside the highlight state condition is: selectionstyle! = ... NO This implementation we use a more direct approach
    • 1: Implement the Selection/deselection method, set the corresponding color inside
    • 2: Overriding the Setselect method
__block and __weakFirst, __block is used to modify a variable, which can be modified in block (see Block implementation principle)
    • __block: Variables modified with __block will be retain in the block code quickly (under ARC, MRC will not retain)
    • __weak: Variables modified with __weak are not retain in block code blocks
At the same time, under ARC, to avoid the block appears circular reference __weak typedof (self) weakself = self;

__block variable in the MRC is not retain when used in block.
But __block in Arc will be retain.
Instead, use __weak or __unsafe_unretained to more accurately describe the purpose of weak reference.
The former can only be used after iOS5, but it is better (after the object is release, this pointer will be set to nil automatically)
The latter is the arc of the environment for a compatible 4.x solution.
So in the example above,

 __block MyClass* temp = …;    // MRC環境下使用 __weak MyClass* temp = …;    // ARC但只支援iOS5.0以上的版本 __unsafe_retained MyClass* temp = …;  //ARC且可以相容4.x以後的版本
    • Atomic atomic operation, the system will lock the setter method. Specific use of @synchronized (self) {//code}
    • Nonatomic does not lock the setter method.
    • Atomic: Thread-safe, requires a lot of system resources to lock up attributes
    • Nonatomic: Non-thread-safe, suitable for small memory mobile devices

iOS Development--full project in combat OC & 11th day of best sister

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.