iOS Learning notes-basic MVC Learning

Source: Internet
Author: User

1. Parameter descriptions for @property
Arc is a set of memory management mechanisms introduced by Apple to simplify the programmer's memory management
Using the arc mechanism, the application and release of objects will be automatically added to the code by the compiler at run time retain and release
1> Strong: An object referenced by a strong pointer that is not released by the system during the life cycle
In OC, objects are strongly pointers by default
2> weak: An object referenced by a weak pointer, the system immediately releases
Weak pointers can point to other objects that have already been referenced by a strong pointer

@property Parameter Usage Summary:
1> Control with weak
2> Property object with strong
3> non-object type with assign
4> string NSString with copy

Tip: When you implement the interface layout in pure hand code, you need to use the strong strong pointer if you are using lazy loading to handle the interface control.

2. How to calculate the layout of nine Gongge
The constants that can be common are extracted as much as possible in order to increase the flexibility of the nine grid layout, as far as possible:
1> automatically adjusts the position and number of small squares based on the data to be displayed
2> once the number of columns to display is adjusted, only a small number of values can be modified to do so

3. Some additions to UIButton
3.1 Types of buttons
In iOS controls, only UIButton provides a class method that allows you to specify different types of buttons when you instantiate a button.
Uibuttontypecustom and [[UIButton alloc] init] are equivalent
3.2 Modifying button fonts
There are two object properties in UIButton that are defined by ReadOnly:
1> Titlelabel
2> ImageView
The ReadOnly in @property indicates that the pointer address of both object properties is not allowed to be modified, but the properties inside it can be modified

Note: Because the font size of the button is common to all States, you can
button.titlelabel.font= [Uifont systemfontofsize:14.0];
Modify the font size of the button label text

However, you cannot use (Button.titleLabel.text = @ "Download";) code to set the text content of the button label, because the text content of the button label is related to the state of the button, and the text of the button's default and highlight state may be different.

4. Block animation

4.1 First-end animations
If you just modify the properties of the control, it is easier to use the end-of-the-ending animation, but it is not so convenient if you need to do a post-processing after the animation is finished.
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration: Duration of animation];
To modify the animation code for a property
// ......
[UIView commitanimations];

4.2 Pieces of animation
Block animation is relatively flexible, especially important is the ability to write animation-related code together, easy to read and understand the code, in iOS basically use block animation
[UIView animatewithduration:2.0 animations:^{
Modifying control Property Animations
Label.alpha = 0.0;
} completion:^ (BOOL finished) {
Delete a control
[Label Removefromsuperview];
}];

5. Dictionary Turn model
5.1 Advantages of the dictionary turn model:
1> reducing the coupling of code
2> all dictionary-to-model parts of the code are centralized in one place, reducing the chance of code errors
3> using the model's attribute manipulation directly in the program to improve coding efficiency

The model should provide a construction method that can pass in the dictionary parameters
-(Instancetype) Initwithdict: (Nsdictionary *) dict;
+ (Instancetype) xxxwithdict: (Nsdictionary *) dict;

5.2 Instancetype & ID
1> instancetype on a type representation, as with an ID, can represent any object type
2> Instancetype can only be used on return value types and cannot be used as an ID on parameter types
One benefit of 3> instancetype than ID: The compiler detects the true type of instancetype

5.3 Adding the ReadOnly property to the model
When you define a property, the Getter&setter method is generated, and an underlined member variable is generated
In the case of the ReadOnly property, only getter methods are generated and no member variables
@property (Nonatomic, Strong, ReadOnly) UIImage *image;

@interface Lfappinfo ()
{
UIImage *_imageabc;
}
-(UIImage *) image
{
if (!_IMAGEABC) {
_IMAGEABC = [UIImage ImageNamed:self.icon];
}
return _IMAGEABC;
}
Reasonable use of read-only attributes in the model can further reduce the coupling of the code.

5.4 Benefits of using the data model:
The caller does not care about any processing details inside the model!

6. XIB
The Xib file can be used to describe a piece of local UI interface
XIB & Storyboard
Same point:
1> are used to describe the software interface
2> are edited with the Interface Builder tool.
Different points
1> Xib is lightweight and is used to describe the local UI interface
2> Storyboard is a heavyweight, a multi-interface for describing the entire software, and can show a jump relationship between multiple interfaces

7. View Packaging Ideas
1> If you have more than one child control inside a view, you will typically consider customizing a view to shield the creation of its inner child controls from the outside world.
2> the outside world can pass the corresponding model data to View,view to get the model data and set the corresponding data for the inner child control.

8. Xcode some common shortcut keys

New
Shift + CMD + N New Project
CMD + N New file

View
Option + cmd + ENTER to open assistant editor
CMD + return display main window
cmd + 0 Navigation window
Option + cmd + 0 tool window

Switch between. M & H control + cmd + up/Down
Switch between control + cmd and around in the order of the Browse files

View header file Control + cmd + j
Switch to the corresponding function control + 6 support smart Input, note input method

Run
CMD + R Run
CMD +. Stop it
CMD + b Compilation
CMD + SHIFT + B static memory analysis compilation to check for memory leaks on the program structure

Layout
Control + I re-indent the selected button
Cmd +] to the right to increase the indent
cmd + [left indent
cmd +/comment/uncomment, tip: When canceling a comment, the comment double slash must be at the beginning of the
Cmd + up to the file open Start position
cmd + down to file end position

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.