无法将实例变量连接到AppDelegate [英] Having trouble hooking up instance variables to AppDelegate
问题描述
使用Xcode4在可视对象编辑器中连接实例变量时遇到一些问题。
Am having some trouble hooking up instance variables in the visual object editor using Xcode4.
已经能够将Whereami App Delegate连接到mapView和activityIndicator,但由于某种原因,找不到locationTitleField。我也无法将代表连接回App Delegate。
Have been able to connect the Whereami App Delegate to the mapView and activityIndicator, but for some reason, can't find the locationTitleField. Am also having trouble connecting the delegates back to the App Delegate.
我做错了什么?
这里是Whereami App Delegate.h的代码:
Here is the code for Whereami App Delegate.h:
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface WhereamiAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate> {
UIWindow *window;
CLLocationManager *locationManager;
IBOutlet MKMapView *mapView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextView *locationTitleField;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
Whereami App Delegate.m
Whereami App Delegate.m
#import "WhereamiAppDelegate.h"
@implementation WhereamiAppDelegate
@synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//-- Create location manager object --
locationManager = [[CLLocationManager alloc] init];
//-- Make this instance of WhereamiAppDelegate the delegate
//-- It will sends its messages to our Whereami delegate.
[locationManager setDelegate:self];
//-- We want all results from the location manager--
[locationManager setDistanceFilter:kCLDistanceFilterNone];
//-- And we want it to be as accurate as possible--
//-- Regardless of how much time/power it takes --
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//-- Tell our location manager to start looking for its location
//-- immediately
[locationManager startUpdatingLocation];
[self.window makeKeyAndVisible];
return YES;
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSLog(@"Could not find location: %@", error);
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"%@", newLocation);
}
推荐答案
尝试将它们设为属性而不是iVars ...
Try making them properties instead of iVars ...
@interface WhereamiAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate>
@property (nonatomic, retain) IBOutlet CLLocationManager *locationManager;
@property (nonatomic, retain) IBOutlet MKMapView *mapView;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) IBOutlet UITextView *locationTitleField;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
并且不要忘记合成它们
@synthesize locationManager = _locationManager;
@synthesize mapView = _mapView;
@synthesize activityIndicator = _activityIndicator;
@synthesize locationTitleField = _locationTitleField;
我从未将iVars用于nib文件中出现的对象;我倾向于总是使用房产,从来没有遇到任何问题与挂钩。
I never use iVars for objects that appear in nib files; I tend to always use properties and have never experienced any issues with hooking up the outlets.
这篇关于无法将实例变量连接到AppDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!