ios 无法实例化名为 MKMapView 的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3522066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:34:40  来源:igfitidea点击:

Could not instantiate class named MKMapView

iosipadmkmapview

提问by tg2

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

创建了一个新的 iPad 项目,在详细信息视图中我添加了一个 MKMapView,将 MapKit.framework 添加到项目中,将属性 / 等添加到标题中。去运行项目并获得一个 SIGABRT

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

****由于未捕获的异常“NSInvalidUnarchiveOperationException”而终止应用程序,原因:“无法实例化名为 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?

我找到了http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/但是,就像我说的,我已经添加了框架。我错过了什么?

回答by JoBu1324

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):

我也遇到了这个问题,但我能够通过按照链接中第 2 步的说明来解决它(顺便说一下,谢谢):

  1. Add the MapKit framework to the project. (Control + Click Frameworks folder -> Add -> Existing Frameworks)
  1. 将 MapKit 框架添加到项目中。(Control + 单击 Frameworks 文件夹 -> 添加 -> 现有框架)

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

我刚刚搜索了 MapKit.framework,将其添加到项目中,错误就消失了。

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

我还没有添加任何地图代码(虽然我在 IB 中有一个 MapViewDelegate 连接),但到目前为止它工作正常!

回答by Alice

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.

单击您的项目以显示项目设置。在目标下,单击您的项目,从上方的工具栏中选择“构建阶段”。在“Link binary With Libraries”选项卡下,您将看到项目中包含的框架列表。单击“+”按钮并将 MapKit 库从显示的列表添加到您的项目中。

回答by marc_aragones

For Xcode 6.1:

对于 Xcode 6.1:

  • Select your project
  • In general tab, look for Linked Frameworks and Libraries(last one)
  • Press + button
  • Search MapKit.framework
  • Finally add
  • 选择您的项目
  • 在常规选项卡中,查找链接的框架和库(最后一个)
  • 按 + 按钮
  • 搜索MapKit.framework
  • 最后添加

回答by tryKuldeepTanwar

Easy way!

简单的方法!

Works above Xcode version 7.2

适用于 Xcode 7.2 以上版本

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.

就我而言,从功能中选择 MAPS 会自动将您的框架链接到您的项目,您所要做的就是检查Capabilities -> Maps 中的 Maps 按钮。

Heres the attached screenshot. Cheers!!

这是附加的屏幕截图。干杯!!

enter image description here

在此处输入图片说明

回答by SumiSadiq

For xCode 4.2:

对于 xCode 4.2:

Click on your project name ->targets ->building Phase ->link binary with library 
  -> click on + sign ->select mapKit.framework ->click add

回答by RonTor

I also received this error when trying to deploy to my 5.1 phone (with XC 4.5), even after changing my deployment target to be 5.1. Looks like the maps update wouldn't fly since I still had Google Maps on my phone. After updating my phone's OS, the exception disappeared.

我在尝试部署到我的 5.1 手机(使用 XC 4.5)时也收到此错误,即使在将我的部署目标更改为 5.1 之后也是如此。看起来地图更新不会飞,因为我的手机上还有谷歌地图。更新我手机的操作系统后,异常消失了。

回答by futureshocked

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)

ld: 警告: 忽略文件 /Users/peter/programming/iPhone/iNspector/MapKit.framework/MapKit,文件是为不受支持的文件格式构建的,这不是所链接的架构 (i386)

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

然后我只是连接了我的 iPhone,在设备上构建和运行,地图就可以工作了。

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

所以看来MapKit框架不能在386架构上编译,需要设备。

回答by ecurb33

In regards to @futureshocked's input, I also came across the

关于@futureshocked 的输入,我也遇到了

Id: warning: ignoring file /blah.../MapKit, file was built for unsupported file format which is not the architecture being linked (i386)

Id:警告:忽略文件 /blah.../MapKit,文件是为不受支持的文件格式构建的,这不是正在链接的体系结构 (i386)

issue.

问题。

**Check to make sure you didn't copy the MapKitframework into your local project directory when you added it to your project. I accidentally did this and XCode was giving me the above error. So I removed it from my project directory (in Finder), recompiled, and everything was normal again.

**检查以确保在将MapKit框架添加到项目时没有将框架复制到本地项目目录中。我不小心这样做了,XCode 给了我上述错误。所以我把它从我的项目目录中(在 Finder 中)删除,重新编译,一切又正常了。

If you don't have the Framework in your project, go ahead and re-link as stated in the answer above.

如果您的项目中没有框架,请继续并按照上述答案中的说明重新链接。

Found a good tutorial on getting started with MapKit:
http://www.youtube.com/watch?v=X-3jM24EIGM&feature=related

找到了一个很好的 MapKit 入门教程:http: //www.youtube.com/watch?v =X-3jM24EIGM&feature =related

回答by Naloiko Eugene

Please import the WebKit at your Build Phases. You need to import the WebKit

请在您的构建阶段导入 WebKit。 您需要导入 WebKit