"Property 'setRegion' not found on object of type MKMapView*" or problem connecting storyboard to the code?

32 Views Asked by At

I am developping an ios app with MapKit zoom to user current location on Xcode 14.0. It failed to build.

The direct error from xcode is "Property 'setRegion' not found on object of type MKMapView*". self.mapView.setRegion(viewRegion, false);

If the line was commented out by

//self.mapView.setRegion(viewRegion, false);

The build succeeds and the app runs on my iPhone.

"setRegion", on the other hand, should exist in MKMapView type according to the apple reference. https://developer.apple.com/documentation/mapkit/mkmapview/1452768-setregion?language=occ

It might be an issue: This program is developped with storyboard. The real problem might be the "connection" between the (objective c) code and storyboard. I made an "outlet" by right click on mapview on storyboard and making a connection to ViewController.h, though.

Do I miss something?

the minimal-set source "maptest03.zip" is uploaded on https://drive.google.com/file/d/11SuZr_2bq9J8KCWWb1981l6e24wTzsvt/view?usp=sharing

Thank you very much! Have a nice day! :)

The source:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    CLAuthorizationStatus status;
    
    locationManager = [[CLLocationManager alloc]init];
    locationManager.delegate = self;

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
        [locationManager requestAlwaysAuthorization];

    //if (locationManager.location.coordinate) {
    CLLocationCoordinate2D userLocation;
    userLocation = CLLocationCoordinate2DMake(35.68154,139.752498);
    
    //userLocation = locationManager.location.coordinate;
        MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(userLocation, 200, 200);
        //self.mapView.setRegion(viewRegion, false);
    //    }

    
    [locationManager startUpdatingLocation];
    [locationManager startUpdatingHeading];
    //Receive all updates
    locationManager.distanceFilter = kCLDistanceFilterNone;
    //Get best possible accuracy
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;

}
0

There are 0 best solutions below