Could not instantiate class named MKMapView

2019-01-31 04:31发布

I may be doing something really stupid here as I've done it before and it worked and now...

Created a new iPad project, in the details view I added a MKMapView, added the MapKit.framework to the project, added the property / etc. to the header. Go to run the project and get a SIGABRT with

****Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named MKMapView'**

I found http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ but, like I said, I've already added framework. What am I missing?

9条回答
甜甜的少女心
2楼-- · 2019-01-31 05:12

I ran into this too, but I was able to get past it by following the instructions of step 2 in your link (thanks, by the way):

  1. Add the MapKit framework to the project. (Control + Click Frameworks folder -> Add -> Existing Frameworks)

I just searched for MapKit.framework, added it to the project, and the error went away.

I haven't added any map code yet (although I do have a MapViewDelegate connected in IB), but it's working fine so far!

查看更多
虎瘦雄心在
3楼-- · 2019-01-31 05:14

Click on your project to bring the project settings. Under Targets, click your project, select from the upper toolbar "Build Phases". Under "Link binary With Libraries" tab, you will see the list of frameworks included in your project. Click the "+" button and add MapKit library from the shown list to your project.

查看更多
爷的心禁止访问
4楼-- · 2019-01-31 05:18

For xCode 4.2:

Click on your project name ->targets ->building Phase ->link binary with library 
  -> click on + sign ->select mapKit.framework ->click add
查看更多
甜甜的少女心
5楼-- · 2019-01-31 05:22

For Xcode 6.1:

  • Select your project
  • In general tab, look for Linked Frameworks and Libraries (last one)
  • Press + button
  • Search MapKit.framework
  • Finally add
查看更多
你好瞎i
6楼-- · 2019-01-31 05:25

Works above Xcode version 7.2 and tested till Verion xCode 10 beta version

As far as I'm concerned selecting the MAPS from capabilities will automatically link your framework to your project all you have to do is Check the Maps Button in Capabilities -> Maps.

Heres the attached screenshot. Cheers!!

enter image description here

查看更多
Animai°情兽
7楼-- · 2019-01-31 05:26

I noticed that I was getting this message (on top of the original one mentioned in this post) when I was building and running on the simulator:

ld: warning: ignoring file /Users/peter/programming/iPhone/iNspector/MapKit.framework/MapKit, file was built for unsupported file format which is not the architecture being linked (i386)

Then I just connected my iPhone, build and ran on the device, and the map worked.

So it seems that the MapKit framework cannot be compiled on the 386 architecture, it needs the device.

查看更多
登录 后发表回答