我想弄清楚如何從另一個類調用函數。我使用的是RootViewController的設置自己的看法作爲一個可以說AnotherViewController從另一個類調用函數 - Obj C
所以在我AnotherViewController即時將添加在.h文件
@class RootViewController
而在.m文件即時將導入查看
#import "RootViewController.h"
我有一個調用的函數:
-(void)toggleView {
//do something }
然後在我的AnotherViewController我分配了一個按鈕:
-(void)buttonAction {
//}
在我想能夠調用該函數toggleView在我的RootViewController的的buttonAction。
有人可以澄清我如何做到這一點。
我嘗試添加這是我buttonAction:
RootViewController * returnRootObject = [[RootViewController alloc] init];
[returnRootObject toggleView];
但我不認爲這是正確的。
謝謝先進。
這不是最有效的方法,完全通過NSNotificationCenter處理類間通信確實不是很好的做法。我真的建議你看一下委託方法或者至少一個單例。 – AriX 2010-06-21 01:27:06