Objective c 如何从ios中的UIViewController类转到委托类
我已经创建了一个privite委托类。我想在单击我的Objective c 如何从ios中的UIViewController类转到委托类,objective-c,ios7,uiviewcontroller,appdelegate,Objective C,Ios7,Uiviewcontroller,Appdelegate,我已经创建了一个privite委托类。我想在单击我的UIViewController类中的按钮时调用此委托类。请给我一次答案。我在这里写的代码一旦plz观察到这一点 -(IBAction)gotoDailPad:(id)sender{ FirstViewApplication *appDelegate = (FirstViewApplication *)[[UIApplication sharedApplication] delegate]; } 要访问应用程序委派,您有权访问:[[U
UIViewController
类中的按钮时调用此委托类。请给我一次答案。我在这里写的代码一旦plz观察到这一点
-(IBAction)gotoDailPad:(id)sender{
FirstViewApplication *appDelegate = (FirstViewApplication *)[[UIApplication sharedApplication] delegate];
}
要访问应用程序委派,您有权访问:
[[UIApplication sharedApplication]委派]
现在要访问委托的方法或成员,请确保它在头(.h)文件中公开。例如,如果要调用在实现(.m)文件中实现的方法,请在.h文件中声明它:
在AppDelegate.h
-(int)getCurrentAppID代码>
在AppDelegate.m
-(int)getCurrentAppID{return 0;}
这就是它的全部。。。从这个意义上讲,应用程序代理没有什么“特殊之处”。如果按照通用标准在代理中导入viewController,效果会更好
#import "viewControler.h"
在代理类中
- 委托类是应用程序的启动,因此建议不要在根目录下返回
试试这个
#import "AppDelegate.h"
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.firstViewController someMethod]
你没有。几乎没有理由这么做。,