如何在单点触控应用程序中存储/访问全局变量?我在 AppDelegate 的 FinishedLaunching 方法期间检索 GPS 位置(使用 Monotouch.CoreLocation.CLLocationManager)。然后,我如何从该 appdelegate 上的属性访问该信息(例如,从视图)?还是有另一种全局数据的首选方法?
更新:我只想在启动时获取一次位置,然后从我的所有视图中访问该位置。这是我的 AppDelegate - 我想从视图中访问 locationManager 字段。我当然可以添加一个属性来这样做,但我想我的问题是“我如何从视图访问该属性(或者我什至可以,考虑到它是一个委托)”?
// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
private CLLocationManager locationManager = new CLLocationManager();
// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
locationManager.Delegate = new GpsLocationManagerDelegate();
locationManager.StartUpdatingLocation();
window.AddSubview (navController.View);
window.MakeKeyAndVisible ();
return true;
}
// This method is required in iPhoneOS 3.0
public override void OnActivated (UIApplication application)
{
}
}