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 6255369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:21:09+00:00 2026-05-24T14:21:09+00:00

I got a method to loop through an XML document. The method has a

  • 0

I got a method to loop through an XML document. The method has a Do-While Loop like this:

do {

    if([[TBXML elementName:element] isEqualToString:@"establishment"]) {

        NSString *establishment= [TBXML textForElement:element];

        NSLog(establishment);

        [establishment release];

    }

    if (element->firstChild) 
        [self traverseElement:element->firstChild];

    // Obtain next sibling element
} while ((element = element->nextSibling));

What i want to do is: Each time the loop passes the node it has to write

[TBXML textForElement:element];

To an UIPickerView. The number of establishments is dynamic, so i never know in advance.

EDIT:

Is this the right way to fill my array?

- (void) traverseElement:(TBXMLElement *)element {
  do {
    if([[TBXML elementName:element] isEqualToString:@"establishment"]) {

    NSString *establishmentName = [TBXML textForElement:element];    
    NSMutableArray *stringsArray;
    [stringsArray addObject:establishmentName];


    }
    // if the element has child elements, process them
    if (element->firstChild) 
        [self traverseElement:element->firstChild];

    // Obtain next sibling element
 } while ((element = element->nextSibling));


}

Because i don’t have a clue where i have to alloc the uipickerview. Should i do that in my method where i am parsing the XML?

And i don’t know where to get the datasource..

  • 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-24T14:21:10+00:00Added an answer on May 24, 2026 at 2:21 pm

    I think you’ll probably want to setup a NSMutableArray that holds all the strings that you want to appear in the UIPickerView.

    To respond to your edit, I would likely create the array in the header file (assuming this is all happening in a UIViewController). Define it as:

    NSMutableArray *stringsArray;
    

    Then in your ViewDidLoad (or init, or loadView) method you’ll want to initialize it. In your code, you are doing so every time it finds an element, so it’s not being persisted and you’ll be creating a whole bunch of 1 element arrays.

    stringsArray = [[NSMutableArray alloc] init]; // do this in -(id)init or (void)viewDidLoad
    

    Then of course you’ll want to release it in your dealloc method (and possibly your ViewDidUnload if you did it in ViewDidLoad).

    Then when you create the UIPickerView, you’ll want to set its data source and delegate to your view controller. In those methods, they will pull from the array that your XML parsing adds elements to, and display them accordingly. Here’s some code to make sense of this:

     myPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480, 320, 216)];
     [myPicker setDelegate:self];
     [myPicker setDataSource:self];
    

    Your header file will look something like this too:

    @interface MyViewController: UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
         NSMutableArray *stringsArray;
    }
    

    You are basically instructing this view controller to supply all the data to your picker view. When the picker view is created, it looks to the following methods to fill in the appropriate data and display the picker view graphically.

    Then here are the datasource methods:

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [stringsArray objectAtIndex:row];
    
    }
    
    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1; // assuming a single spinning wheel of strings (not split into left/right for example)
    }
    
    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [stringsArray count]; // the number of strings that your parser finds and adds to the array
    }
    

    I think after your parser finds things, if it’s adding them while the picker view is on screen, you’ll want to call reload on it:

    [myPicker reloadAllComponents];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone else run into this problem before? I've got a method that calls
I've got a program that executes a method through a Thread.Start. The method has
I have an expression like this Expression<Func<IInterface, object>> How do i loop/traverse through all
I've got a method similar to this, which loops through one set of data
I never seem to get this right. I've got a method that returns a
I've got a curious item, I'm trying to enumerate through an xml file with
I've got models like this: class PledgeItem(models.Model): title = models.CharField(...) usd_amount = models.DecimalField(...) class
Basically, I've got a custom class that has a draw method that draws a
I have got method which is using Assembly.LoadFrom(...) statement and returns the supported cultures
I've got a Method that gets a IDictionary as a parameter. Now I want

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.