Load plist data in controller
1, set property nsarray or variable group Nsmutablearray
@property (Nonatomic,strong) Nsarray *message;
2, rewrite get method, lazy load, get plist data
1-(nsarray*) messages{2 if(_messages==Nil) {3 //load the dictionary data in plist4 //bundle contains all the resources of the iOS program5nsstring* Path=[[nsbundle Mainbundle] Pathforresource:@"messages.plist"Oftype:nil];6 //an absolute path is generally passed to the end of Offile in iOS7nsarray* dictarray=[Nsarray Arraycontentsoffile:path];8 //Dictionary Arrays--model arrays9Nsmutablearray *messagearray=[Nsmutablearray array];Ten for(Nsdictionary *dictinchDictarray) { One //the model provides a way to receive nsdictionary initialization using KVC ALxlmessage *message=[Lxlmessage messagewithdict:dict]; - [Messagearray addobject:message]; - } the_messages=Messagearray; - } - Retrun _messages; -}
iOS knowledge points