i want load data tableview web service in iphone application. outputs working correctly table doesn't contain data. empty.
i did not find mistake in application. why doesn't tableview load data web service ?
scoreclass.h
@interface scoreclass : nsobject { iboutlet nsinteger *scoreid; iboutlet nsinteger *userscore; iboutlet nsinteger *gameid; iboutlet nsstring *macid; iboutlet nsstring *nickname; iboutlet boolean *isdeleted; iboutlet nsdate *createdon; iboutlet nsdate *modifiedon; nsmutablearray *scorelist; } @property(assign, readwrite) nsinteger *scoreid; @property(assign, readwrite) nsinteger *userscore; @property(assign, readwrite) nsinteger *gameid; @property(nonatomic, retain) nsstring *macid; @property(nonatomic, retain) nsstring *nickname; @property(nonatomic, assign) boolean *isdeleted; @property(nonatomic, retain) nsdate *createdon; @property(nonatomic, retain) nsdate *modifiedon; @property(retain, readwrite) nsmutablearray *scorelist; @end
scoreclass.m
#import "scoreclass.h" @implementation scoreclass @synthesize scoreid, userscore, gameid, macid, nickname, isdeleted,createdon, modifiedon,scorelist; -(id)init { [super init]; macid = [nsstring stringwithformat:@""]; nickname= [nsstring stringwithformat:@""]; return self; } -(void) dealloc{ [macid release]; [nickname release]; [super dealloc]; } @end
scorewebservice.h
#import <uikit/uikit.h> #import "scoreclass.h" @interface scorewebservice : uiviewcontroller { // request nsstring *address; nsstring *xmlnamespace; nsstring *operation; nsstring *parameters; nsmutablestring *incomevalue; // connection bool recordresults; bool connectionfinished; // xml parsing nsmutablestring *soapresults; nsmutabledata *webdata; nsxmlparser *xmlparser; scoreclass *score; nsmutablearray *scorelist; } @property(nonatomic, retain) nsstring *address; @property(nonatomic, retain) nsstring *xmlnamespace; @property(nonatomic, retain) nsstring *operation; @property(nonatomic, retain) nsstring *parameters; @property(nonatomic, retain) nsmutablestring *incomevalue; @property(retain, readwrite) nsmutablearray *scorelist; @property(nonatomic, retain) scoreclass *score; @end
scorewebservice.m
#import "scorewebservice.h" @implementation scorewebservice @synthesize operation, parameters, address, xmlnamespace, incomevalue, score; @synthesize scorelist; -(id)init { [super init]; address = [nsstring stringwithformat:@""]; xmlnamespace = [nsstring stringwithformat:@""]; operation = [nsstring stringwithformat:@""]; parameters = [nsstring stringwithformat:@""]; incomevalue = [nsstring stringwithformat:@""]; score = [[scoreclass alloc]init]; scorelist = [[nsmutablearray alloc]init]; return self; } -(nsmutablearray *)scoretablewebservice{ if (([address isequaltostring:@""]) || ([xmlnamespace isequaltostring:@""]) || ([operation isequaltostring:@""])) { //return; } recordresults = false; 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/\">" "<soap:body>" "<bayisatistakiptablo6oku xmlns=\"http://trigonservis.com/\">" "<istasyonkodu>34005</istasyonkodu>" "<gun1>02.01.2012</gun1>" "</bayisatistakiptablo6oku>" "</soap:body>" "</soap:envelope>" ]; nslog(@"request soap = \n%@\n\n", soapmessage); nsurl *url = [nsurl urlwithstring:address]; nsmutableurlrequest *therequest = [nsmutableurlrequest requestwithurl:url]; [therequest addvalue: @"text/xml; charset=utf-8" forhttpheaderfield:@"content-type"]; [therequest addvalue: @"http://trigonservis.com/bayisatistakiptablo6oku" forhttpheaderfield:@"soapaction"]; [therequest addvalue: soapmessage forhttpheaderfield:@"content-length"]; [therequest sethttpmethod:@"post"]; [therequest sethttpbody: [soapmessage datausingencoding:nsutf8stringencoding]]; //connexion nsurlconnection *theconnection = [[nsurlconnection alloc] initwithrequest:therequest delegate:self]; if( theconnection ) { webdata = [[nsmutabledata data] retain]; } else { nslog(@"there problem connect webservices"); } while (!connectionfinished) { [[nsrunloop currentrunloop] runmode:nsdefaultrunloopmode beforedate:[nsdate distantfuture]]; } return scorelist; } -(void)connectiondidfinishloading:(nsurlconnection *)connection { nsstring *thexml = [[nsstring alloc] initwithbytes: [webdata mutablebytes] length:[webdata length] encoding:nsutf8stringencoding]; #if(target_iphone_simulator) nslog(@"reponse soap = \n%@\n\n", thexml); #endif [thexml release]; // appel futur du parser if(xmlparser) [xmlparser release]; // allocation du nsxmlparser xmlparser = [[nsxmlparser alloc] initwithdata: webdata]; // désigne l'instance de la classe courante comme étant le delegate du nsxmlparser [xmlparser setdelegate: self]; [xmlparser setshouldresolveexternalentities: yes]; [xmlparser parse]; [connection release]; [webdata release]; connectionfinished = true; } /************************************************************************************ ** connection */ -(void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response { [webdata setlength: 0]; } -(void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data { [webdata appenddata:data]; } -(void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error { [connection release]; [webdata release]; } /************************************************************************************ ** xml parsing */ -(void)parser:(nsxmlparser *)parser didstartelement:(nsstring *)elementname namespaceuri:(nsstring *) namespaceuri qualifiedname:(nsstring *)qname attributes: (nsdictionary *)attributedict { nslog(@"elementname = %@ \n", elementname); if( [elementname isequaltostring:@"dagiticisatis"]) { if(!soapresults) soapresults = [[nsmutablestring alloc] init]; recordresults = true; } else if( [elementname isequaltostring:@"istasyonadi"]) { if(!soapresults) soapresults = [[nsmutablestring alloc] init]; recordresults = true; } return; } -(void)parser:(nsxmlparser *)parser foundcharacters:(nsstring *)string { if( recordresults ){ [soapresults appendstring: string]; } } -(nsmutablearray *)parser:(nsxmlparser *)parser didendelement:(nsstring *)elementname namespaceuri:(nsstring *)namespaceuri qualifiedname:(nsstring *)qname { if( [elementname isequaltostring:@"dagiticisatis"]) { #if(target_iphone_simulator) nslog(@"scoreid = %@ \n", soapresults); #endif score = [[scoreclass alloc]init]; score.macid = soapresults; [soapresults release]; soapresults = nil; } else if( [elementname isequaltostring:@"istasyonadi"]){ #if(target_iphone_simulator) nslog(@"istasyonadi = %@ \n", soapresults); #endif score.nickname = soapresults; [soapresults release]; soapresults = nil; } return scorelist; } @end
gridtableviewcell.h
#import <uikit/uikit.h> @interface gridtableviewcell : uitableviewcell { uicolor *linecolor; bool topcell; uilabel *cell1; uilabel *cell2; uilabel *cell3; } @property (nonatomic, retain) uicolor* linecolor; @property (nonatomic) bool topcell; @property (readonly) uilabel* cell1; @property (readonly) uilabel* cell2; @property (readonly) uilabel* cell3; @end
gridtableviewcell.m
#import "gridtableviewcell.h" #define cell1width 80 #define cell2width 80 #define cellheight 44 @implementation gridtableviewcell @synthesize linecolor, topcell, cell1, cell2, cell3; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { self = [super initwithstyle:style reuseidentifier:reuseidentifier]; if (self) { topcell = no; // add labels 3 cells cell1 = [[uilabel alloc] initwithframe:cgrectmake(0, 0, cell1width, cellheight)]; cell1.textalignment = uitextalignmentcenter; cell1.backgroundcolor = [uicolor clearcolor]; // important set or lines not appear [self addsubview:cell1]; cell2 = [[uilabel alloc] initwithframe:cgrectmake(cell1width, 0, cell2width, cellheight)]; cell2.textalignment = uitextalignmentcenter; cell2.backgroundcolor = [uicolor clearcolor]; // important set or lines not appear [self addsubview:cell2]; cell3 = [[uilabel alloc] initwithframe:cgrectmake(cell1width+cell2width, 0, 320-(cell1width+cell2width), cellheight)]; // note - hardcoded 320 not ideal; can done better cell3.textalignment = uitextalignmentcenter; cell3.backgroundcolor = [uicolor clearcolor]; // important set or lines not appear [self addsubview:cell3]; } return self; } - (void)setselected:(bool)selected animated:(bool)animated { [super setselected:selected animated:animated]; // configure view selected state } - (void)dealloc { [cell1 release]; [cell2 release]; [cell3 release]; [super dealloc]; } - (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetstrokecolorwithcolor(context, linecolor.cgcolor); // cgcontextsetlinewidth: default line width 1 unit. when stroked, line straddles path, half of total width on either side. // therefore, 1 pixel vertical line not draw crisply unless offest 0.5. problem not seem affect horizontal lines. cgcontextsetlinewidth(context, 1.0); // add vertical lines cgcontextmovetopoint(context, cell1width+0.5, 0); cgcontextaddlinetopoint(context, cell1width+0.5, rect.size.height); cgcontextmovetopoint(context, cell1width+cell2width+0.5, 0); cgcontextaddlinetopoint(context, cell1width+cell2width+0.5, rect.size.height); // add bottom line cgcontextmovetopoint(context, 0, rect.size.height); cgcontextaddlinetopoint(context, rect.size.width, rect.size.height-0.5); // if topmost cell in table, draw line on top if (topcell) { cgcontextmovetopoint(context, 0, 0); cgcontextaddlinetopoint(context, rect.size.width, 0); } // draw lines cgcontextstrokepath(context); } - (void)settopcell:(bool)newtopcell { topcell = newtopcell; [self setneedsdisplay]; } @end
1 set delegate table.
2 assign data web service nsmutablearray.
3 write method mentioned below.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { //create cell here
}
4 call
[tblview reloaddata];
Comments
Post a Comment