Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display the data on the table view which are fetched from the web service in iphone
    primarykey
    data
    text
    <p>I am using the following code to fetch the data from the web service,</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. recordResults = FALSE; NSString *soapMessage = [NSString stringWithFormat: @"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n" "&lt;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/\"&gt;\n" "&lt;soap:Body&gt;\n" "&lt;GetContacts xmlns=\"http://tempuri.org/\"&gt;\n" "&lt;loginid&gt;nareshreddyyaradla.net@gmail.com&lt;/loginid&gt;\n" "&lt;/GetContacts&gt;\n" "&lt;/soap:Body&gt;\n" "&lt;/soap:Envelope&gt;\n",loginId.text ]; NSLog(soapMessage); NSURL *url = [NSURL URLWithString:@"http://www.xxxxxx.net/services/contacts.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/GetContacts" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; NSHTTPURLResponse *urlResponse = nil; NSError *error = [[NSError alloc] init]; NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&amp;urlResponse error:&amp;error]; NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"Response Code: %d",[urlResponse statusCode]); if([urlResponse statusCode] &gt;= 200 &amp;&amp; [urlResponse statusCode] &lt; 300) { NSLog(@"Response: %@", result); } if( theConnection ) { webData = [NSMutableData data]; } else { NSLog(@"theConnection is NULL"); } } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSURLResponse *)response { [webData setLength:0]; } -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"ERROR with theConnection"); } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"DONE. Received Bytes: %d", [webData length]); NSString *theXML = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding]; NSLog(theXML); if( xmlParser ) { } xmlParser = [[NSXMLParser alloc] initWithData:webData]; [xmlParser setDelegate:self]; [xmlParser setShouldResolveExternalEntities:YES]; [xmlParser parse]; } -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"GetContactsResult"]) { if(!soapResults) { soapResults = [[NSMutableString alloc] init]; } recordResults = TRUE; } } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if( recordResults ) { [soapResults appendString:string]; } } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"GetContactsResult"]) { recordResults = FALSE; greeting.text = soapResults; soapResults = nil; } } </code></pre> <p>The following is the data which i am getting in the console,</p> <pre><code>&amp;lt;normalcontacts&amp;gt; &amp;lt;table_id&amp;gt;1788&amp;lt;/table_id&amp;gt; &amp;lt;table_name&amp;gt;nareshaug11&amp;lt;/table_name&amp;gt; &amp;lt;total_contact&amp;gt;48&amp;lt;/total_contact&amp;gt; &amp;lt;created_date&amp;gt;2011-08-11T01:24:00-07:00&amp;lt;/created_date&amp;gt; &amp;lt;/normalcontacts&amp;gt; &amp;lt;normalcontacts&amp;gt; &amp;lt;table_id&amp;gt;1730&amp;lt;/table_id&amp;gt; &amp;lt;table_name&amp;gt;nareshtodayjuly28&amp;lt;/table_name&amp;gt; &amp;lt;total_contact&amp;gt;2&amp;lt;/total_contact&amp;gt; &amp;lt;created_date&amp;gt;2011-07-27T23:01:00-07:00&amp;lt;/created_date&amp;gt; &amp;lt;/normalcontacts&amp;gt; &amp;lt;normalcontacts&amp;gt; &amp;lt;table_id&amp;gt;1685&amp;lt;/table_id&amp;gt; &amp;lt;table_name&amp;gt;naresh2&amp;lt;/table_name&amp;gt; &amp;lt;total_contact&amp;gt;0&amp;lt;/total_contact&amp;gt; &amp;lt;created_date&amp;gt;2011-07-07T22:12:00-07:00&amp;lt;/created_date&amp;gt; &amp;lt;/normalcontacts&amp;gt; &amp;lt;normalcontacts&amp;gt; &amp;lt;table_id&amp;gt;1596&amp;lt;/table_id&amp;gt; &amp;lt;table_name&amp;gt;todaymay26&amp;lt;/table_name&amp;gt; &amp;lt;total_contact&amp;gt;0&amp;lt;/total_contact&amp;gt; &amp;lt;created_date&amp;gt;2011-05-26T03:24:00-07:00&amp;lt;/created_date&amp;gt; &amp;lt;/normalcontacts&amp;gt; &amp;lt;normalcontacts&amp;gt; &amp;lt;table_id&amp;gt;667&amp;lt;/table_id&amp;gt; &amp;lt;table_name&amp;gt;my contacts&amp;lt;/table_name&amp;gt; &amp;lt;total_contact&amp;gt;1&amp;lt;/total_contact&amp;gt; &amp;lt;created_date&amp;gt;2010-07-19T23:13:00-07:00&amp;lt;/created_date&amp;gt; &amp;lt;/normalcontacts&amp;gt; </code></pre> <p>I need to display the table_name in the UITableView, i followed the following examples, <a href="http://wwwiphoneresourcesbyemme-rajesh.blogspot.in/2012/04/web-services-example-using-nsxml-parser.html" rel="nofollow">http://wwwiphoneresourcesbyemme-rajesh.blogspot.in/2012/04/web-services-example-using-nsxml-parser.html</a> but i was not able to display it on the tableView.</p> <p>TableView Code,</p> <pre><code>- (void)parserDidEndDocument:(NSXMLParser *)parser{ UITableView *tab = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain]; tab.delegate = self; tab.dataSource = self; [self.view addSubview:tab]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [namedata count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [[UITableViewCell alloc] init]; cell.textLabel.text=[arrareasdata objectAtIndex:indexPath.row]; cell.imageView.image=[array objectAtIndex:indexPath.row]; tableView.separatorColor=[UIColor greenColor]; cell.textLabel.textColor=[UIColor blackColor]; return cell; } </code></pre> <p>Any suggestions or links will be appreciated, Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload