0

I've built up a test project with NSOperation and NSOperationQueue. There is only one textbox: @property (weak) IBOutlet NSTextField *textbox;

In the background this is performed:

- (void)main
{
    NSURL *url = [NSURL URLWithString:@"http://google.com"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(@"MainThread: %@", ([NSThread isMainThread] ? @"YES" : @"NO"));
        [[AppDelegate sharedManager] performSelectorOnMainThread:@selector(pageLoaded:)
                                           withObject:response
                                        waitUntilDone:NO];
}

And the selector that is called on the main thread:

- (void)pageLoaded:(NSString*)document
{
    [textbox setStringValue:document]; // does nothing
    NSLog(@"Textbox: %@", textbox); // returns nil
}

Why is textbox returning nil?

ronalchn
  • 12,225
  • 10
  • 51
  • 61

1 Answers1

0

Mmm, I have two ideas:

  1. A realistic one: [AppDelegate sharedManager] returns different object from one you have called applicationDidFinishLaunching on. It's possible if AppDelegate is added onto the XIB + you have a separate singleton instance.
  2. A mystic one: there is only one AppDelegate, but the property value is nullified somewhy. If this is the case, the simplest way to figure the thing out would be to change the "weak" to "assign" (to find out whether it's releasing issue), than re-define setTextbox to find who calls it.

But I can bet it's #1.

Gobra
  • 4,263
  • 2
  • 15
  • 20
  • 1. On both places AppDelegate has same address. I'm really stuck on this one :)) – EduardMarcinco Aug 30 '12 at 19:52
  • OK, what about #2 - is the setTexbox called anywere? Also, I have another idea (#3) - the pageLoaded is called BEFORE the awakeFromNib. I.e. the actual view isn't yet loaded and the outlet is not set yet as well. – Gobra Aug 31 '12 at 15:28