Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3284728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:11:13+00:00 2026-05-17T20:11:13+00:00

I start process of getting data from viewDidLoad and populate NSMutableArray with that data.

  • 0

I start process of getting data from viewDidLoad and populate NSMutableArray with that data. But when I want to populate UIPicker I cant because there is no more data in that array. How did I lost that??? Please help 🙁

@synthesize activityIndicator;
@synthesize pckCountries;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad { 

 countriesList = [[NSMutableArray alloc] initWithCapacity:20]; 
 [self getCountriesList];

 NSLog(@"%@", [countriesList count]);


 [super viewDidLoad];

}

- (void)dealloc {
 [activityIndicator release];
    [xmlParser release];
    //[soapResults release];

    [super dealloc];
}

- (void) getCountriesList{


 NSString *soapMsg = 
 [NSString stringWithFormat:
  @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  "<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>"
  "<getCountries xmlns=\"http://www.smsbug.com/api/\" />"
  "</soap:Body>"
  "</soap:Envelope>"
  ];

 NSURL *url = [NSURL URLWithString: 
      @"http://www.smsbug.com/api/webservice.asmx"];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
 NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
 [req addValue:@"text/xml; charset=utf-8" 
forHTTPHeaderField:@"Content-Type"];
    [req addValue:@"http://www.smsbug.com/api/getCountries" 
forHTTPHeaderField:@"SOAPAction"];
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];   
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
 conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if (conn) {
        webData = [[NSMutableData data] retain];


  } 
}

-(void) connection:(NSURLConnection *) connection 
didReceiveResponse:(NSURLResponse *) response {
 [webData setLength: 0];
}

-(void) connection:(NSURLConnection *) connection 
 didReceiveData:(NSData *) data {
 [webData appendData:data];
 NSLog(@"%@", webData);
}

-(void) connection:(NSURLConnection *) connection 
  didFailWithError:(NSError *) error {
 [webData release];    
 [connection release];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
    NSLog(@"DONE READING WEATHER WEB SERVICE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] 
                        initWithBytes: [webData mutableBytes] 
                        length:[webData length] 
                        encoding:NSUTF8StringEncoding];
    //---shows the XML to test---
    NSLog(theXML);    

    [theXML release]; 

 // stop activity indicator animation
    [activityIndicator stopAnimating];    


 //-----------------------------------------------------------------
 // start parsing received XML message
 //-----------------------------------------------------------------
 if (xmlParser)
 {
  [xmlParser release];
 }
 xmlParser = [[NSXMLParser alloc] initWithData: webData];
 [xmlParser setDelegate:self]; 
 [xmlParser setShouldResolveExternalEntities:YES];
 [xmlParser parse];

 // clear memory
    [connection release];
    [webData release];
}

-(void) parser:(NSXMLParser *) parser 
didStartElement:(NSString *) elementName 
  namespaceURI:(NSString *) namespaceURI 
 qualifiedName:(NSString *) qName
 attributes:(NSDictionary *) attributeDict {

 //NSLog(elementName);
 if ([elementName isEqualToString:@"Country_Name"])
 {  
  countryFound = YES;
 }
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{      

  if([string isEqualToString:@"Data Not Found"])
  {
   errorOccured = YES;
  }
  else if(countryFound == YES)
  {   
   //NSLog(string);
   [countriesList addObject:string];

  }
  else
  { 
   [soapResults appendString: string];
  }     
}

-(void)parser:(NSXMLParser *)parser 
didEndElement:(NSString *)elementName 
 namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName
{
 if(errorOccured == YES)
 { 
  UIAlertView *alert = [[UIAlertView alloc] 
         initWithTitle:@"No Data!"                           
         message:@"Sorry"
         delegate:self  
         cancelButtonTitle:@"OK" 
         otherButtonTitles:nil];
  [alert show];
  [alert release];
  [soapResults setString:@""];  
  errorOccured = FALSE;
 }
 else
 {  
  if ([elementName isEqualToString:@"Country_Name"])
  {   
   countryFound = FALSE;
  }  
 }
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
 return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ 
 return countriesList.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
 return [countriesList objectAtIndex:row];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:11:13+00:00Added an answer on May 17, 2026 at 8:11 pm
    1. [super viewDidLoad] should be the first invocation in a viewDidLoad method.
    2. There’s a leak – you should invoke [countriesList release] in a dealloc method.
    3. NSURLRequest is asynchronous. As well as NSXMLParser. So all picker delegate methods will be called before downloading/parsing is finished. Thus, in all delegate methods you should check if countriesList is equal to nil.
    4. When parsing is finished (implement parserDidEndDocument: method to receive this message) you should explicitly call [picker reloadAllComponents].
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's common knowledge that using System.Diagnostics.Process.Start is the way to launch a url from
I'm trying to install a service using InstallUtil.exe but invoked through Process.Start . Here's
I have a simple Tray icon program that opens a site using System.Diagnostics.Process.Start(URL) And
If I start a process via Java's ProcessBuilder class, I have full access to
I'm using this article to start a process on a remote machine using WMI.
I am actually trying to start a process for winzip and zip a folder.
Kind of a special case problem: I start a process with System.Diagnostics.Process.Start(..) The process
I've got in an ASP.NET application this process : Start a connection Start a
Sometimes when I try to start Firefox it says a Firefox process is already
My Sharepoint 2007 web part executes code to start a K2 workflow process. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.