iphone - 应用程序代理访问

标签 iphone

对于旧版本的 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?

欢迎 Ant 评论

最佳答案

不知道你心里有什么误解。但我在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];
}

附注:正如迈克尔指出的 UIResponder 继承自 NSObject 所以你不必担心。一切都一样。

关于iphone - 应用程序代理访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10051778/

相关文章:

iphone - 检测对象上的坐标并将其输出到 NSLog

iphone - 如何在 UIWebView 加载其内容时显示加载消息?

iphone - 存储多个 View Controller 共有的数据

iphone - 裁剪图像后,保存的图像质量降低

iphone - NSMutableArray 在索引处从其他数组添加对象

iphone - 企业应用数据安全

iPhone通讯录问题

ios - iAD 未按预期工作

iphone - 打印区域设置名称

iphone - 如何在 iphone 中将 NSArray 数据分配给 NSMutableArray?