首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AppDelegate访问

AppDelegate访问
EN

Stack Overflow用户
提问于 2012-04-07 12:34:08
回答 3查看 5.7K关注 0票数 5

对于旧版本的xcode/ios,我使用:

代码语言:javascript
复制
appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate];

访问AppDelegate

代码语言:javascript
复制
#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?

欢迎蚂蚁评论

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-04-07 12:57:21

我不知道你有什么误解。但我在iOS 5应用程序开发中使用的仍然是一样的。

根据你上面的评论,你说你写了这段代码:

代码语言:javascript
复制
#import "AppDelegate.h"
@property (nonatomic,retain) AppDelegate *appDelegate;  // This line is unnecessary

您不必为AppDelegate类的对象创建属性。只需在您想要访问全局变量.m文件中包含以下行:

代码语言:javascript
复制
// Create an AppDelegate variable in your MapViewScreen @interface
AppDelegate *appDelegate;

#import "AppDelegate.h"
@implementation MapViewScreen

- (void)viewDidLoad  
{
    appDelegate = [[UIApplication sharedApplication] delegate];
}

P.S.:正如Michael指出的那样,继承了,所以你不必担心。一切都是一样的。

票数 9
EN

Stack Overflow用户

发布于 2012-04-07 12:56:30

你不需要修改iOS 5的任何东西,因为UIResponder class继承自NSObject。

票数 4
EN

Stack Overflow用户

发布于 2012-04-07 12:37:32

是的,您可以使用访问appDelegate时使用的相同工具。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10051778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档