Invoke method in another class

左心房为你撑大大i 提交于 2019-12-13 03:29:47

问题


I have two view controllers (viewControllerA and viewControllerB) with their own views. When the user touches a button in the view of viewControllerA, I am able to load the view of the viewControllerB.

However, I don't know how to invoke a method in viewControllerB's class!


回答1:


Without much info to go on I'll assume that both A & B are of the same class (though they wouldn't have to be). You could always declare a property that would then point from one to the other:

MyViewController.h:

@interface MyViewController : UIViewController {
    MyViewController *altViewController;
}

@property (nonatomic, retain) MyViewController *altViewController
@end

Just be sure that once instantiated you populate that property with a pointer to the other VC. Then you can easily call a method on the other view controller simply by: [altViewController doMethod];



来源:https://stackoverflow.com/questions/1186620/invoke-method-in-another-class

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