我是Objective C的新手,并试图在Xcode中创建一个基本的地图应用程序。我一直在(void)mapView
方法
Invalid argument type 'void' to unary expression
这是我的代码,
- (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];
}
造成这种情况的原因是什么?
答案 0 :(得分:2)
您在}
功能上错过了右括号(viewDidLoad
)。更正后,它应如下所示(请参阅THIS!!!
注释的行):
- (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];
}
由于缺少大括号,编译器认为您的mapView:didUpdateUserLocation
函数定义是viewDidLoad
函数中的表达式,而不是函数定义。我猜这可能不是你想要的。