Third-party, resolving a model cannot pass a value after acquiring network data

Source: Internet
Author: User

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

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.