1
我想知道是否有可能在AppDelegate类创建一个自定义的委托,像这样的实例:有可能在AppDelegate中创建一个自定义委托?
@protocol AppDelegateDelegate <NSObject>
- (void)finishSync:(BOOL)success;
@end
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
@property (nonatomic, weak) id <AppDelegateDelegate> delegate;
@end
有可能创造这样的事情?通知为该代表注册的课程?
编辑 我该如何使用委托?例如,如果我这样做:
#import "AppDelegate.h"
@interface MasterViewController : UIViewController <AppDelegateDelegate>
@end
.M
@implementation MasterViewController
...
- (void)viewDidLoad {
AppDelegate *appController = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appController.customDelegate = self;
}
中我只停留在这一观点的作品,但例如,如果我在SecondViewController具有相同的代码来实现委托切换,代理不再在MasterViewController中工作......我错了什么?
好的谢谢!你按照我的问题:) – Piero
感谢您的接受。我想我以前回答过你的一个问题。我遵循SO中的大部分问题。 :) – iDev
如果我想用其他视图中的委托,我该如何使用它?我必须这样做? AppDelegate * appController =(AppDelegate *)[[UIApplication sharedApplication] delegate]; appController.customDelegate = self;代码中的任何地方?或者我必须在@interface的头文件中声明appController? – Piero