Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone AppDelegate访问_Iphone - Fatal编程技术网

Iphone AppDelegate访问

Iphone AppDelegate访问,iphone,Iphone,对于旧版本的xcode/ios,我使用了: appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate]; 访问AppDelegate的步骤 #import "AppDelegate.h" @property (nonatomic,retain) AppDelegate *appDelegate; #import <UIKit/UIKit.h> @interface AppDelega

对于旧版本的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
#导入“AppDelegate.h”
@属性(非原子,保留)AppDelegate*AppDelegate;
#进口
@接口AppDelegate:UIResponder{
}
@属性(强,非原子)UIWindow*window;
@结束
//-----
#进口
#导入“AppDelegate.h”
@接口详细信息控制器:UIViewController{
}
@属性(非原子,保留)AppDelegate*AppDelegate;
@结束
但在ios5中,AppDelegate从NSObject更改为UIRepsNoder

是否可以访问AppDelegate


欢迎ant评论

是的,您可以使用与访问appDelegate相同的东西

iOS 5无需更改任何内容。继承自NSObject。

我不知道你心中有什么误解。但我在iOS5应用程序开发中使用的仍然是相同的

根据您上面的评论,您说您编写了以下代码:

#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.:正如迈克尔所指出的继承自,所以你不必担心。一切都一样。

我写道:#导入“AppDelegate.h”@property(非原子,保留)AppDelegate*AppDelegate;