对于旧版本的xcode/ios,我使用:
appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];访问AppDelegate
#import "AppDelegate.h"
@property (nonatomic,retain) AppDelegate *appDelegate;
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
}
@property (strong, nonatomic) UIWindow *window;
@end
//-----
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface DetailController : UIViewController{
}
@property (nonatomic,retain) AppDelegate *appDelegate;
@end但在ios5 AppDelegate中,从NSObject更改为UIRepsonder
是否可以访问AppDelegate?
欢迎蚂蚁评论
发布于 2012-04-07 12:57:21
我不知道你有什么误解。但我在iOS 5应用程序开发中使用的仍然是一样的。
根据你上面的评论,你说你写了这段代码:
#import "AppDelegate.h"
@property (nonatomic,retain) AppDelegate *appDelegate; // This line is unnecessary您不必为AppDelegate类的对象创建属性。只需在您想要访问全局变量.m文件中包含以下行:
// Create an AppDelegate variable in your MapViewScreen @interface
AppDelegate *appDelegate;
#import "AppDelegate.h"
@implementation MapViewScreen
- (void)viewDidLoad
{
appDelegate = [[UIApplication sharedApplication] delegate];
}P.S.:正如Michael指出的那样,继承了,所以你不必担心。一切都是一样的。
发布于 2012-04-07 12:56:30
你不需要修改iOS 5的任何东西,因为UIResponder class继承自NSObject。
发布于 2012-04-07 12:37:32
是的,您可以使用访问appDelegate时使用的相同工具。
https://stackoverflow.com/questions/10051778
复制相似问题