Learn iOS Development UI Chapter--MVC design interface and model conversion of data

Source: Internet
Author: User

1. Dictionary Turn model

========================================

Benefits of 1.1 dictionary to model:

1 > Reduce the coupling of the Code

2 > All Dictionary-to-model sections of code are centralized in one place, reducing the chance of code errors

3 > Direct use of the model's attribute operations 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;

1.2instancetype & 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

3> instancetype One more benefit: The compiler detects the true type of instancetype

1.3 Adding readonly properties to the model

// defines a property, the Getter&setter method is generated, and an underlined member variable is generated

// and if it is the readonly property, only the getter method is generated and no member variable

@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.

1.4 Benefits of using the data model:

* * * caller does not care about any processing details inside the model!

2. XIB

========================================

The Xib file can be used to describe a piece of local UI interface

XIB & Storyboard

Same point:

1 > is 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

3. View Packaging Ideas

========================================

1 > If you have more than one child control inside a view , you will typically consider customizing a viewto shield the creation of its inner child controls from the outside world.

2 > the outside world can pass in the corresponding model data to the view, theview gets the model data and sets the corresponding data to the inner child control.

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.