xcode - iOS: Passing parsed values from soap webservice in NSObject class back to UIViewController -
i don't know why being difficult can't work. here's simple problem:
i have uiviewcontroller calls paring class type of nsobject class parsing jobs.
i need parsed data values returned viewcontroller.
could body provide me simple step or suggestion this... need issue solved project , deadline near...
thanks here code:
viewcontroller.m
@implementation viewcontroller - (void)viewdidload { [super viewdidload]; wsclass *ws = [[wsclass alloc] init]; [ws initparsing]; } wsclass.h
@interface projlistclass : nsobject @property(nonatomic,strong) nsstring * project_id; @property(nonatomic,strong) nsstring * short_descr; @property(nonatomic,strong) nsstring * location; @end; @interface wsclass : nsobject <nsxmlparserdelegate>{ projlistclass *proj_obj; projlistclass *prj; nsmutabledata* webdata; nsmutablestring *soapresults; nsurlconnection *conn; nsxmlparser *xmlparser; } @property(nonatomic,strong) nsmutablearray * arrhouses; @property(nonatomic, strong) nsxmlparser *xmlparser; -(void) initparsing; @end wsclass.m
#import "wsclass.h" @implementation projlistclass @synthesize project_id, short_descr, location; @end @implementation wsclass @synthesize arrhouses, xmlparser; -(void) initparsing{ [uiapplication sharedapplication].networkactivityindicatorvisible = yes; soapresults = [[nsmutablestring alloc] init]; arrhouses=[[nsmutablearray alloc]init]; nsstring *soapmessage = [nsstring stringwithformat: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" "<soap:envelope xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlns:xsd=\"http://www.w3.org/2001/xmlschema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" "<soap:body>\n" "<projects_list xmlns=\"http://tempuri.org/\"/>\n" "</soap:body>\n" "</soap:envelope>\n"]; nsurl *url = [nsurl urlwithstring:@"http://192.168.0.10:8056/wservices.asmx"]; nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:url]; nsstring *msglength = [nsstring stringwithformat:@"%d", [soapmessage length]]; [therequest addvalue: @"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"]; [therequest addvalue: @"http://tempuri.org/projects_list" forhttpheaderfield:@"soapaction"]; [therequest addvalue: msglength forhttpheaderfield:@"content-length"]; [therequest sethttpmethod:@"post"]; [therequest sethttpbody: [soapmessage datausingencoding:nsutf8stringencoding]]; conn = [[nsurlconnection alloc] initwithrequest:therequest delegate:self]; if( conn ) { webdata = [nsmutabledata data]; } else { nslog(@"theconnection null"); } } .... .... .... -(void)connectiondidfinishloading:(nsurlconnection *)connection { nsstring *thexml = [[nsstring alloc] initwithbytes: [webdata mutablebytes] length:[webdata length] encoding:nsutf8stringencoding]; if (xmlparser) { xmlparser=nil; } xmlparser = [[nsxmlparser alloc] initwithdata: webdata]; [xmlparser setdelegate: self]; [xmlparser setshouldresolveexternalentities:yes]; [xmlparser parse]; } .... .... .... -(void)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { ..... ..... ..... else if([elementname isequaltostring:@"projectslistdetails"]) { [arrhouses addobject:proj_obj]; proj_obj=nil; } soapresults = nil; soapresults = [[nsmutablestring alloc]init]; }
see below steps give idea
1) inside nsobject class parsingmodel class, create protocol inside parsing class doing parsing. give name whatever want.
@protocol webserviceresponsedelegate <nsobject> @optional - (void)didrecieveresponsedata:(nsmutablearray*)array; @end implement protocol parsing class @protocol webserviceresponsedelegate;
create property inside parsing class set delegate confirming class..
@property (nonatomic, assign) id<webserviceresponsedelegate>delegate; and need send parsed data confirming class i.e created parsing object
//say didrecieveresponse method called when completed parsing of data // - (void)didrecieveresponse // { // if([delegate respondstoselector:@selector(didrecieveresponsedata)]) // { // //pass populated datasource have parsed data. // [delegate didrecieveresponsedata:parseddata]; // // parseddata numtablearray or other datasource. //} edit: see below delegate method called when finished paring successfully
- (void)parserdidenddocument:(nsxmlparser *)parser{ //pass populated datasource have parsed data. //before check whether delegate method confirmed class. if([delegate respondstoselector:@selector(didrecieveresponsedata)]) { [delegate didrecieveresponsedata:parseddata]; } // parseddata numtablearray or other datasource. } // called when parser has completed parsing. if encountered, parse successful.you need call 2) , inside confirming class said uiviewcontroller dataviewcontroller define delegate method in dataviewcontroller.h adopt protocol dataviewcontroller<webserviceresponse>
and set delegate point @ creating parsing model class
parsingmodel * paring = [parsingmodel alloc]init]; [paring setwebserviceresponsedelegate:self]; //definition of callback delegate method - (void)didrecieveresponsedata:(nsmutablearray*)array { //here have parsed data can use want } i hope clear you.
Comments
Post a Comment