我在我的app delegate中声明了一个变量:
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>{
CLLocationManager *locationManager;
}
@property(nonatomic, strong) PFGeoPoint *shovelLocation;
我在我的AppDelegate中合成了它:
@interface AppDelegate ()
@end
@implementation AppDelegate
@synthesize shovelLocation;
我已将AppDelegate.h文件导入到我试图从以下位置访问此对象的其他viewcontroller文件中:
#import "AppDelegate.h"
问题在于,当我创建appDelegate对象并尝试访问其属性时,它表示它没有shovelLocation属性:
//get location
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
PFGeoPoint *location = appDelegate.shovelLocation;
^
Property 'shovelLocation' not found on object of type 'AppDelegate *'
这不是我正在创建的AppDelegate的真实实例,还是我错过了一些明显的东西?
答案 0 :(得分:0)
不确定这是否可以解决您的问题,但请尝试保留而不是强力
@property (nonatomic, retain) PFGeoPoint *shovelLocation;
此外,不需要演员。 (AppDelegate中*)
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
答案 1 :(得分:0)
在Appdelegate.h
文件中编写以下代码:
@property(nonatomic, strong) PFGeoPoint *shovelLocation;
+(AppDelegate *)sharedAppDelegate;
并在Appdelegate.m
+(AppDelegate *)sharedAppDelegate
{
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
并编写代码以调用此变量:
AppDelegate *app=[AppDelegate sharedAppDelegate];
PFGeoPoint *location = app.shovelLocation;
它正在运行,使用它!