Referencing UIViewController in NSObject
I am trying to access UIViewController's view in a NSObject class. The NSObject class is suppose to programmatically change UIViewController's user interface. I tried accessing NSViewController's view in NSObject by using self.view but was told that "request for member 'view' in something not a structure or union.
After a few inquiries, I was told that I need to reference viewController开发者_运维百科 in my NSObject class. I am unsure of how to do this and would appreciate any help or point in the right direction. Thanks!
You should give the NSObject class a property called myController
or something in its interface declaration, or pass a ViewController*
to any methods that need to access it.
For the property, you can say:
ViewController* myController;
in the NSObject sub-class interface declaration, or for the method way, add an argument to your NSObject sub-class' method:
- (void) someMethodThatTakesAViewController: (ViewController*) theViewController {
//Do your stuff here
theViewController.view = [[UIView alloc] init]; // Or whatever you want to do
}
Hope this was what you were looking for.
精彩评论