开发者

Having trouble hooking up instance variables to AppDelegate

Having trouble hooking up instance variables to AppDelegate

Am having some trouble hooking up instance variables in the visual object editor using Xcode4.

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.

What am I doing wrong?

Here is the code for Whereami App Delegate.h:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface WhereamiAppDelegate : NSObject     <UIAppl开发者_开发百科icationDelegate,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

#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);
}


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

and don't forget to synthesize them

@synthesize locationManager = _locationManager;
@synthesize mapView = _mapView;
@synthesize activityIndicator = _activityIndicator;
@synthesize locationTitleField = _locationTitleField;

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜