Access IBOutlet from other class (ObjC)

﹥>﹥吖頭↗ 提交于 2019-11-28 13:04:37

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.

Erik

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!