Import this third party
Model.h1#import<Foundation/Foundation.h>2 @classModel;3 4 @protocolModeldelegate <NSObject>5 6-(void) Didmodel: (model*) Model Receivearray: (nsarray*) array; 7 @end 8 9 @interfaceModel:nsobjectTen One@property (nonatomic,copy) NSString *Code; A@property (nonatomic,copy) NSString *Julogo; -@property (nonatomic,copy) NSString *Juslogo; -@property (nonatomic,copy) NSString *Jubanner; the@property (nonatomic,copy) NSString *jubrand_id; -@property (nonatomic,copy) NSString *name; -@property (nonatomic,copy) NSString *Judiscount; -@property (nonatomic, weak)ID<ModelDelegate>Delegate; + - +- (void) Getdatawithurl: (NSString *) URL; A @end
MODEL.M1 #import "Model.h" 2 #import "AFNetworking.h" 3 4 @interfaceModel ()5 @end 6 7 @implementationModel8 9- (void) Getdatawithurl: (NSString *) URL {Ten OneNsmutablearray *data_array = [Nsmutablearray arraywithcapacity:0]; A -Afhttprequestoperationmanager *manager =[Afhttprequestoperationmanager manager]; -[Manager Post:url Parameters:nil success:^ (afhttprequestoperation *operation,IDresponseobject) { theNsarray *array = responseobject[@"Data"]; -Sleep3); - for(Nsdictionary *dicinchArray) - { +Model *datamodel =[Model Alloc]init]; -[Datamodel setvaluesforkeyswithdictionary:dic]; +[Data_array Addobject:datamodel]; A at } - - if(self.)Delegate&& [Self.Delegaterespondstoselector: @selector (Didmodel:receivearray:)]) { -[Self.Delegatedidmodel:self Receivearray:data_array]; - } - in} failure:^ (Afhttprequestoperation *operation, Nserror *error) { -NSLog (@"Error---%@", error); to }]; + } - the @end
VIEWCONTROLLER.M1 #import "ViewController.h" 2 #import "Model.h" 3 #import "AFNetworking.h" 4 #import "MBProgressHUD.h" 5 6 @interfaceViewcontroller () <ModelDelegate> { 7Mbprogresshud *_hud;8Model *model;9 }Ten @end One A @implementationViewcontroller - -- (void) Viewdidload the { -[Super Viewdidload]; - -Model =[[Model alloc] init]; +Model.Delegate=Self ; -[Model Getdatawithurl:@"http://zhekou.repai.com/jinrituangou/view/jupinpai_list.php"]; dispatch_queue_t queue = Dispatch_queue_create ("Showhud", NULL); +Dispatch_async (Queue, ^{ ADispatch_async (Dispatch_get_main_queue (), ^{ at[Self Showhud:@"Loading ..."]; - }); - }); - } - --(void) Showhud: (nsstring*) Title { in if(_hud) { -[_hud Hide:yes]; to_hud =Nil; + } -_hud = [Mbprogresshud showhudaddedto:[[[uiapplication sharedapplication]Delegate] [window] animated:yes]; the_hud.labeltext =title; *[_hud Show:yes]; $ }Panax Notoginseng --(void) Closehud { the + A[_hud Hide:yes]; the } + --(void) Didmodel: (model*) Model Receivearray: (nsarray*) Array { $ //NSLog (@ "Receive array:%@", array); $[self closehud]; - -[self logwitharray:array]; the - }Wuyi the- (void) Logwitharray: (Nsarray *) array{ -Sleep3); WuNSLog (@"%@", array); - } About @end
Third-party, resolving a model cannot pass a value after acquiring network data