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

  • Home
  • SEARCH
  • 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 6149293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:25:41+00:00 2026-05-23T19:25:41+00:00

Some code instead of a long explanation. The problem is : When called from

  • 0

Some code instead of a long explanation.
The problem is :

When called from viewDidLoad, the server call triggers the delegates methods (connectionDidFinishLoading, etc…). But when called from XMLFileFullParsed, the request is launched to the server, but those same methods are not triggered.

If i call [self loadXMLDatas] instead of threading it, both server calls work fine.

Why ?

I start here :

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundaTag:) name:@"foundaTag" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(XMLFileFullParsed:) name:@"XMLFileFullParsed" object:nil];

    self.server = [[ServerCommManager alloc] initWithServer:@"http://someserver/"];
    [self.server sendQuestionWithCallIdentifier:@"IDENTIFIER" onPage:@"testpage.php" withParams:nil sendAnswerToObject:self];  // -- This one works 

    [NSThread detachNewThreadSelector:@selector(loadXMLDatas) toTarget:self withObject:nil];
}

- (void) loadXMLDatas {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
Do things, create a XMLparser, start to parse.
[pool release];
}

- (void) XMLFileFullParsed:(NSNotification*)notification {

    [self.server sendQuestionWithCallIdentifier:@"IDENTIFIER" onPage:@"testpage.php" withParams:nil sendAnswerToObject:self]; // -- This one doesn't work
}

XMLParser.m

- (void) doYourJob {
    [self doTheJob];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"XMLFileFullParsed" object:nil userInfo:nil];
}

- (void) doTheJob:(XMLTag*)tag {
    if ([tag.name isEqualToString:@"searchedtag"]) {
       theData = extract some datas
       [[NSNotificationCenter defaultCenter] postNotificationName:@"foundaTag" object:self userInfo:[NSDictionary dictionaryWithObject:theData forKey:@"data"]];
        return;
    }

    for (XMLTag* aTag in tag.childtags) {
        [self doTheJob:aTag];
    }
}

Deep inside the server comm.m

- (void) executeRequest  {
   some init
self.connection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
}

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response  {

}

- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data  
{

}

- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error 
{

}

- (void)connectionDidFinishLoading:(NSURLConnection*)connection 
{

}
  • 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-23T19:25:42+00:00Added an answer on May 23, 2026 at 7:25 pm

    From the code you’ve given, the notification is being posted from another Thread rather than the Main Thread where you’ve registered the observer.

    In Apple’s Notification Documentation, it says

    In a multithreaded application, notifications are always delivered in the thread in which the notification was posted, which may not be the same thread in which an observer registered itself.

    What you can do is move the notification into it’s own method and then use performSelectorOnMainThread like so:

    - (void) doTheJob:(XMLTag*)tag {
        if ([tag.name isEqualToString:@"searchedtag"]) {
           theData = extract some datas
           [self performSelectorOnMainThread:@selector(sendNotification:) withObject:theData waitUntilDone:YES];
            return;
        }
    
        for (XMLTag* aTag in tag.childtags) {
            [self doTheJob:aTag];
        }
    }
    
    - (void)sendNotification:(NSArray *)theData {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"foundaTag" object:self userInfo:[NSDictionary dictionaryWithObject:theData forKey:@"data"]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen some code where a Class is imported, instead of a namespace, making
I have some trivial code that looks like this: SortedDictionary<String, long> d = new
I'm editing some Python code with rather long functions and decided it would be
I am required to make some changes in an existing long C source code.
I rewriting some code that i written a long time ago. The code is
I have some socket connection code that makes use of boost::asio which reads from
i have a splash screen that has some code that i only want called
Some code for context: class WordTable { public: WordTable(); ~WordTable(); List* GetListByAlphaKey(char key); void
Some code for context: class a { } class b { public a a{get;set;}
some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out

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.