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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:20:01+00:00 2026-05-13T19:20:01+00:00

I have a viewController which imports XMLParser.h as the class xmlParser I’m passing an

  • 0

I have a viewController which imports XMLParser.h as the class xmlParser

I’m passing an NSURL object in my viewController to the xmlParser class with the getXML method below

goButton is the button I tap to call the getXML method below. I disable the button which I tapped to trigger the getXML method, but I’m not sure where to put the code to enable it again once the xmlParser has finished parsing the returned XML.

- (IBAction) getXML {
    goButton.enabled = NO;

    // allocate and initialize the xmlParser 
    xmlParser = [[XMLParser alloc] init];

// then generate the URL we are going to pass to it and call the fetchXML method passing the URL.
    NSURL *xmlurl = [[NSURL alloc] initWithString:@"http://www.mysite.com/myfile.xml"];
    [xmlParser fetchXMLFromURL:xmlurl];

    // release objects
    [xmlurl release];
    [xmlParser release];

}

As per @Squeegy recommendation, I modified my code.

- (IBAction) getXML {
    goButton.enabled = NO;

    xmlParser = [[XMLParser alloc] init];

    [self performSelectorInBackground:@selector(parseInBackground:) withObject:xmlParser];

}

- (void)parseInBackground:(XMLParser*)parser {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSURL *xmlurl = [[NSURL alloc] initWithString:@"http://www.mysite.com/myfile.xml"];

    [parser fetchXMLFromURL:xmlurl];
    [self performSelectorOnMainThread:@selector(didFinishXMLParsing:) withObject:parser];

    [xmlurl release];
    [pool drain];

}

- (void)didFinishXMLParsing:(NSXMLParser*)parser {
    goButton.enabled = YES;
}

Looks to be working until it gets to the line

[self performSelectorOnMainThread:@selector(didFinishXMLParsing:) withObject:parser];

The compiler complains as follows:

2010-02-17 00:22:20.574 XMLApp[2443:521b] *** -[viewController performSelectorOnMainThread:withObject:]: unrecognized selector sent to instance 0x1285a0
2010-02-17 00:22:20.578 XMLApp[2443:521b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[viewController performSelectorOnMainThread:withObject:]: unrecognized selector sent to instance 0x1285a0'
2010-02-17 00:22:20.583 XMLApp[2443:521b] Stack: (
    861696817,
    860329709,
    861700631,
    861203093,
    861166272,
    18715,
    846004025,
    845672609,
    848189713
)
  • 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-13T19:20:02+00:00Added an answer on May 13, 2026 at 7:20 pm
    - (IBAction)getXML {
        goButton.enabled = NO;
    
        xmlParser = [[XMLParser alloc] init];
        NSURL *xmlurl = [[NSURL alloc] initWithString:@"http://www.mysite.com/myfile.xml"];
        [xmlParser fetchXMLFromURL:xmlurl];
    
        [self performSelectorInBackground:@selector(parseInBackground) withObject:xmlParser];
    
        [xmlurl release];
        [xmlParser release];
    }
    
    - (void)parseInBackground:(NSXMLParser*)parser {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
        [parser parse];
        [self performSelectorOnMainThread:@selector(didFinishXMLParsing:)
                               withObject:parser
                            waitUntilDone:NO];
    
        [pool drain];
    }
    
    - (void)didFinishXMLParsing:(NSXMLParser*)parser {
        goButton.enabled = YES;
    }
    

    The trick is to do the processing on a background thread, which allows the UI to do stuff. When parsing is done, you have to make any UI changes back on the main thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class for button which was added to my project workspace. I
I have a ViewController which implements a refreshData method In this ViewController, I add
i have view controller which contains a button which show the image library ,if
I have a ViewController class called GamePlay. In GamePlay there is a nested class
I have a method which has gotten a little long & I want to
I have the following ViewController class #import <UIKit/UIKit.h> @interface SampleViewController : UIViewController { IBOutlet
So below is my code for my controller, which I have four of one
I have a ViewController which has an embedded UIImageView . Another ViewController has a
I have two xib files and for each it's own class which overrides UIViewController
I have a table view controller which doesn't let me manually scroll to 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.