Situation One: geocoding
Storyboard
The code is as follows (the project does not import the Mapkit framework, but the running program does not crash):
1 #import "ViewController.h"2 #import<CoreLocation/CoreLocation.h>3 4 @interfaceViewcontroller ()5@property (Weak, nonatomic) Iboutlet Uitextfield *addresstf;6@property (Weak, nonatomic) Iboutlet UILabel *Longitudelabel;7@property (Weak, nonatomic) Iboutlet UILabel *Latitudelabel;8@property (Weak, nonatomic) Iboutlet UILabel *Detaillabel;9 Ten @end One A @implementationViewcontroller - -- (void) Viewdidload { the [Super Viewdidload]; - //additional setup after loading the view, typically from a nib. - } - + //geo-coding --(ibaction) GeoCode { + //Create a Geocoding object AClgeocoder * Geocoder =[[Clgeocoder alloc]init]; at - if(Self.addressTF.text = =Nil) { - return ; - } - -[Geocoder geocodeAddressString:self.addressTF.text completionhandler:^ (nsarray<clplacemark *> * _nullable Placemarks, Nserror *_nullable Error) { in if(Error) { -NSLog (@"%@", error); to return ; + } - //get the landmark Clplacemark the for(Clplacemark * Placemarkinchplacemarks) { *Self.longitudeLabel.text = [NSString stringWithFormat:@"%f", Placemark.location.coordinate.longitude]; $Self.latitudeLabel.text = [NSString stringWithFormat:@"%f", Placemark.location.coordinate.latitude];Panax NotoginsengSelf.detailLabel.text = Placemark.name;//Specific place Names -NSLog (@"%@", placemark.locality);//City Name the } + A }]; the + - } $ $ @end
Scenario two: Adding a map view
Storyboard
Code (the project did not import the framework, but the program crashed):
1 #import "ViewController.h"2 #import<MapKit/MapKit.h>3 4 @interfaceViewcontroller ()5 6 @end7 8 @implementationViewcontroller9 Ten- (void) Viewdidload { One [Super Viewdidload]; A //additional setup after loading the view, typically from a nib. - } - the -- (void) didreceivememorywarning { - [Super didreceivememorywarning]; - //Dispose of any resources the can be recreated. + } - + A @end
Program Crash error:
Terminating app due to uncaught exception ' nsinvalidunarchiveoperationexception ', Reason: ' Could not instantiate class Named Mkmapview '
After you import the Mapkit framework, you can run it successfully.
Why do some times collapse and sometimes not?
Because after XCode5, after you #import <MapKit/MapKit.h>, the program helps the programmer to import the framework by default. But since the program runs in scenario two, the first step is to go to the controller that the arrow in the storyboard is pointing to. A Mkmapview control was found, and the program did not automatically import the frame at that time, so it crashed. In the scenario one, the control in storyboard does not involve any related controls, but instead uses the Corelocation-related method After importing the header file into the code, and the program has automatically helped us to import the framework, so it does not crash.
So, as long as the frame outside of Uikit is used in storyboard, it must be imported manually in the project.
Not importing frames Why sometimes crashes sometimes don't crash