2, the IOS Development dictionary to model and Xib

Source: Internet
Author: User

Dictionary to model (plist file)

Encapsulation method of the model: (Put in the Code warehouse)

1. Add the attribute name corresponding to the key value of the Plist file in the. h file

--- > NSArray--- > NSDictionarystring---> NSStringnumber---> NSNumber

Note: The key value in the attribute name and plist must be consistent

Strong weak copy assign for properties in the 2..h file file

1> strong : 用于一般的对象或自定义的对象类型2> weak : 用于UI控件和delegate3> copy : 用于NSStringblock对象4> assign : 用于基本数据类型

3. Add a constructor that can pass in the dictionary parameter in. h

- (instancetype)initWithDict:(NSDictionary*)dict;+ (instancetype)xxxWithDict:(NSDictionary*)dict;

4. Implementing the corresponding construction method in the. m file

// 在initWithDict:方法中用KVC一句代码搞定所有属性

The difference between 5.instancetype and ID

1> same point: can be used as the return value type of the method
2> different points: The Instancetype compiler detects the true type, and the ID can be used on the parameter type

Second, KVC

KVC-Key-value coding is a method of indirectly modifying/reading object properties
1. Precautions for use:

1> plist中的键值名称必须与模型中的属性一致2> 模型中的属性可以不完全出现在plist中,但是如果plist文件中的属性不完全出现在属性中就会出错。
Third, the use of xib

The Xib file is used to describe a local UI interface
In the development phase for developers is the Xib file, installed on the mobile phone Xib file will be converted to nib file

How to load 1.xib files
1> Method 1: Create all the Xib objects, and put the objects in order in the OBJS array

NSArray * objs = [[NSBundle mainBundle] loadNibNamed:@"appView" owner:nil options:nil];

2> Method 2

UINib *nib = [UINib nibWithNibName:@"appView" bundle:[NSBundle mainBundle]];NSArray* objs = [nib instantiateWithOwner:nil options:nil];

The process of 2.xib encapsulation into view

1>Create a new integrated wordUIViewThe CustomView, assuming that the class name is called (Wbappview)2>Create a newWbappview.XibFile to describeWbappviewInternal structure3>ModifyXibis of typeWbappviewThe true type of4>With the inner child controlWbappviewTo make a property connection5>WbappviewProvides a model property6>overriding model properties.SetMethod, because theSetMethod can be used to get the model data passed by the outside7>Take the model data apart and set the data to the corresponding child controls8>Add: Provide a CreateWbappviewclass method that will read theXibFile Code screen up
Four, lazy loading
    • Lazy loading: Used to load, implemented in the Get method, the Get method in OC is to remove the underscore property name first letter lowercase
      When used: The real data is used or the Get method (document) is used
- (Nsarray*) apps{if(_apps = =Nil) {//1. Get the full path of the plist    NSString*path = [[NSBundleMainbundle] pathforresource:@"App.plist"OfType:Nil];//2. Loading Arrays    Nsarray*dictarray = [NsarrayArraywithcontentsoffile:path];//3. Convert all dictionaries inside the Dictarray into model objects and put them in a new array    Nsmutablearray*apparray = [NsmutablearrayArray]; for(nsdictionary*dict in Dictarray) {//3.1. Create a Model objectMjapp *app = [Mjapp appwithdict:dict];//3.2. Adding model objects to the array[Apparray Addobject:app]; }//4. Assigning Values_apps = Apparray; }return_apps;}

Add: You cannot interact with a control

1> alpha0.012> hiddenYES3> userInteractionNO(父控件的userInteractionNO)4> 位置超过了所在父控件的尺寸// 父视图不能交互,子视图也不能交互方法的命名规范:

Naming laws:

1> 单词首字母小写,后面的单词的首字母大写2> initWithxxxinit 初始化函数With单词必须大写,因为OC默认的就是"驼峰法",默认初始化函数就是init单词开头的,如果是initwithxxx就是认为是initwith单词开头的,造成找不到初始化方法3> 方法,属性不能以new作为名称的开头

"'

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

2, the IOS Development dictionary to model and Xib

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.