首页 文章

一元减2的错误类型参数

提问于
浏览
-1

我的WhereamiAppDelegate.m文件中出现此错误:

#import "WhereamiAppDelegate.h"

@implementation WhereamiAppDelegate

@synthesize window;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Create location manager object -
    locationManager = [[CLLocationManager alloc]init];

    //Make this instance of WhereamiAppDelegate the delegate
    //It will send its messages to our WhereamiAppDelegate
    [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 manager to start looking for its location immediately
    [locationManager startUpdatingLocation];

    [locationManager startUpdatingLocation];

- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation 
    {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
        [mv setRegion:region animated:YES];
    }
    if(TARGET_IPHONE_SIMULATOR){
        [newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
    }

     [mapView setShowsUserLocation:YES];
    - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
    {
        MKAnnotationView *annotationView = [views objectAtIndex:0];
        id ,MKAnnotation> mp = [annotationView annotation];
        MKCoordinateRegion region =

        MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250); [mv setRegion:region animated:YES];
    }


    [self.window makeKeyAndVisible];

    return YES;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"%@",newLocation);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"Could not find location: %@", error);
}


- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

造成麻烦的两种方法是:

- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation 
    {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
        [mv setRegion:region animated:YES];
    }
    if(TARGET_IPHONE_SIMULATOR){
        [newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
    }

     [mapView setShowsUserLocation:YES];
    - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
    {
        MKAnnotationView *annotationView = [views objectAtIndex:0];
        id ,MKAnnotation> mp = [annotationView annotation];
        MKCoordinateRegion region =

        MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250); [mv setRegion:region animated:YES];
    }

这会产生“一元减2的错误类型参数”错误 .

你能告诉我这是什么问题吗?

TIA

1 回答

  • 0

    您似乎在-mapView的主体周围缺少一些:didUpdateUserLocation:方法:

    - (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation 
    {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
        [mv setRegion:region animated:YES];
    }
    
    if(TARGET_IPHONE_SIMULATOR){
        [newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
    }
    [mapView setShowsUserLocation:YES];
    

    应该是:

    - (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation 
    {
        MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([userLocation coordinate], 250, 250);
        [mv setRegion:region animated:YES];
    
        if(TARGET_IPHONE_SIMULATOR){
            [newLocation initWithLatitude:37.33168900 longitude:-122.03073100];
        }
    
        [mapView setShowsUserLocation:YES];
    }
    

相关问题