/**
* 1. Set the model data to be displayed on the controller (set its properties according to the plist file, and then define and implement the factory method to quickly implement the dictionary-to-model)
*/
//1. Model Shop.h file
@interface Shop:nsobject@property (nonatomic, Strong) NSString *name, @property (nonatomic, Strong) NSString *icon;-(Sho P *) Initwithdict: (Nsdictionary *) dict;+ (Shop *) Shopwithdict: (Nsdictionary *) dict; @end
3. shop.m File
#import" Shop.h "@implementation shop-(Shop *) Initwithdict: (Nsdictionary *) Dict{if (self = [super init]) {[Self setvaluesforkeyswithdictionary:dict];} return self;} + (Shop *) Shopwithdict: (nsdictionary *) Dict{return [[Self alloc] initwithdict:dict];} @end
/**
* 2. Create a new class to manage Xib files is actually to manage the child controls on the Xib, and then define and implement a factory method that quickly creates a custom control through xib loading. Override the Set method of model data to initialize control data on a custom control presentation
*/
Note: At this point you will define the class Jpshopview to manage the Jpshopview.xib file, set the class to Xib's "Custom Class" property
1> You need to have a model data Because you're going to be able to show the data to the custom control.
2> Override the set method of the model property to set the data presentation effect on the custom control
[parse: To better show the data to the custom control, you might want to set the data action , directly set to the custom control inside the solution, not to the outside too much exposure, at this time, you think you already have a model data, it is easy to show the data to the custom control, as long as the property is overridden by the Set method (because you have to understand, I will certainly get the data before the display of the custom control up, So the premise is, you pass the data to me and assign it to me. The custom control has the property model, and the property's set method is called, so we can simply override the property's set method to get the model data in it and initialize all the data on the controls on the custom control directly. OU)]
//1. JPShopView.h
@class shop; @interface Jpshopview:uiview@property (Weak, nonatomic) Iboutlet Uiimageview *iconview; @property (weak, non Atomic) Iboutlet UILabel *nameview, @property (nonatomic, strong) Shop *shop;+ (Instancetype) Shopview; @end
2. jpshopview.m
#import "JPShopView.h" #import "Shop.h" @implementation jpshopview+ (instancetype) Shopview{return [[NSBundle Mainbundle] loadnibnamed:@ "Jpshopview" Owner:nil Options:nil] lastobject];} -(void) Setshop: (Shop *) Shop{_shop = Shop;self.iconview.image = [UIImage ImageNamed:self.shop.icon]; Self.nameView.text = Self.shop.name;} @end
/**
* 3. In the controller , get the data that will be displayed on the view, and then show it to the custom control and other controls.
Let the controller have a collection of models, override the Get method of the Model collection properties, and then create the custom control directly, taking the specified model settings to the custom control,
Allow the custom control to be added to the controller's view.
*/
1> gets the data that will be displayed on the view: You might be able to get the data by parsing an array dictionary of the plist file, then you need to set a model array property to store the data in the Plist file
You need to implement the Get method of this property to implement lazy loading effect, so as to avoid excessive waste of resources.
2> then you can define a custom control and then show the model to you:
* Initializes a custom control.
* Get a model data and assign a value to the model properties of the custom control.
* Add a custom control to the controller's view.
1. Define the custom control Jpshopview *shopview = [Jpshopview shopview];//2. Set the model data for the custom control Shopview.shop = self.shops[index];//3. Computes the custom control added to the controller's view on the Frameshopview.frame = CGRectMake (subviewx, Subviewy, Subviewwidth, 70);
5. Add the built-in custom controls to the controller's view
[Self.view Addsubview:shopview];
Custom View Control (1-xib instance code)