Access IBOutlet from other class (ObjC)

后端 未结 2 1192
庸人自扰
庸人自扰 2020-12-11 12:16

I\'ve googled around and found some answers but I didn\'t get any of them to work. I have one NSObject with the class \"A\" and a second class \"B\" without an NSObject. In

相关标签:
2条回答
  • 2020-12-11 13:08

    When you write:

    I have one NSObject with the class "A" and a second class "B" without an NSObject.

    It tells me that you don't have your head around the basic concepts. Read through Apple's objective-C introduction, and the tutorial projects.

    0 讨论(0)
  • 2020-12-11 13:11

    The solution is using NSNotificationCenter. Here's a thread telling you how to do it: Send and receive messages through NSNotificationCenter in Objective-C?

    Then in the method reacting to the notification, you call a method accessing the Outlet

    - (void) receiveTestNotification:(NSNotification *) notification
    {
    
        if ([[notification name] isEqualToString:@"TestNotification"])
            //NSLog (@"Successfully received the test notification!");
            [self performSelectorOnMainThread:@selector(doIt:) withObject:nil waitUntilDone:false];
    }
    - (void) doIt
    {
        //testLabel.text = @"muhaha";
    }
    

    This worked for me, I hope it does so for you as well.

    0 讨论(0)
提交回复
热议问题