문제

I am new to Objective C and trying to make a basic map application in Xcode. I keep getting this error on (void)mapView method,

Invalid argument type 'void' to unary expression 

Here is my code,

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mapView.delegate = self;
}

//H+ adding to have scale adjusted
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

}

What is causing this?

도움이 되었습니까?

해결책

You're missing the closing brace (}) on your viewDidLoad function. Corrected, it should look like this (see the line with the THIS!!! comment):

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.mapView.delegate = self;
} // <-- THIS!!!

//H+ adding to have scale adjusted
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}

As a result of the missing brace, the compiler thinks that your mapView:didUpdateUserLocation function definition is an expression within the viewDidLoad function, not a function definition. I'm guessing that's probably not what you intended.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top