我有一个 UITableViewCell,它有一个 map View 作为 subview 。创建了一个自定义类来处理所有操作,例如添加注释、委托(delegate)等,并将其命名为 CustomeMap.swift。
在 Cell Xib 中将 map View 的类名更改为 CustomeMap 后,应用程序在 CustomeMap 的 因为我还没有实现那个方法。后来我添加了如下方法:initWithCoder 方法中有时会崩溃
import UIKit
import MapKit
protocol CustomeMapDelegate{
func annotationClickEvent(info:NSDictionary?)
}
class CustomeMap: MKMapView,MKMapViewDelegate,CLLocationManagerDelegate {
var locationManager:CLLocationManager?
var delegate1:CustomeMapDelegate?
var tap:UITapGestureRecognizer?
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func awakeFromNib()
{
if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways {
self.showsUserLocation = true;
}
else
{
locationManager = CLLocationManager()
locationManager?.delegate = self;
if locationManager!.respondsToSelector("requestAlwaysAuthorization")
{
locationManager?.requestAlwaysAuthorization()
}
}
self.delegate = self
self.userInteractionEnabled = true
tap = UITapGestureRecognizer(target: self, action: "calloutAction:")
}
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus)
{
if(status == CLAuthorizationStatus.AuthorizedAlways)
{
self.showsUserLocation = true;
}
}
func skipTouch()
{
}
class func createAnnotationForDict(temp:NSDictionary)->MyPointAnnotation
{
var venue = temp.valueForKey("venue") as? NSDictionary
var lat = venue!.valueForKey("latitude") as! Double
var lon = venue!.valueForKey("longitude") as! Double
var venueName = venue!.valueForKey("name") as! String
var dealName = temp.valueForKey("title") as? String
var coord:CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0)
coord.latitude = lat
coord.longitude = lon
var point = MyPointAnnotation()
point.userInfo = temp
point.coordinate = coord
point.title = dealName
point.subtitle = venueName
return point
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!
{
if annotation is MKUserLocation {
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
pinView!.animatesDrop = true
pinView!.pinColor = .Red
var assImg = UIImageView(image: UIImage(named: "r_arrow_g"))
assImg.frame = CGRectMake(0, 0, 16, 16)
assImg.contentMode = UIViewContentMode.ScaleAspectFit
pinView!.rightCalloutAccessoryView = assImg
}
else {
pinView!.annotation = annotation
}
return pinView
}
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!)
{
if view.annotation.isKindOfClass(MKUserLocation){ return }
if let t1 = tap
{
}
else
{
tap = UITapGestureRecognizer(target: self, action: "calloutAction:")
}
view.addGestureRecognizer(tap!)
}
func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!)
{
if view.annotation.isKindOfClass(MKUserLocation){ return }
view.removeGestureRecognizer(tap!)
}
func calloutAction(sender:UITapGestureRecognizer)
{
if(delegate1 != nil)
{
var view = sender.view as! MKAnnotationView
var ann = view.annotation as! MyPointAnnotation
delegate1!.annotationClickEvent(ann.userInfo)
}
}
}
还是一样的问题。
Crash log
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000001
Thread : Crashed: com.apple.main-thread
0 libGPUSupportMercury.dylib 0x2b7228fe gpus_ReturnNotPermittedKillClient
1 libGPUSupportMercury.dylib 0x2b7233cb gpusSubmitDataBuffers
2 libGPUSupportMercury.dylib 0x2b723249 gldCreateContext
3 GLEngine 0x2717191b gliCreateContextWithShared
4 OpenGLES 0x2724dab3 -[EAGLContext initWithAPI:properties:] + 406
5 OpenGLES 0x2724d86f -[EAGLContext initWithAPI:sharedWithCompute:] + 142
6 VectorKit 0x2fc2d58b ggl::OESContext::OESContext(ggl::GLDevice*, std::__1::shared_ptr<ggl::OESSharegroup>) + 530
7 VectorKit 0x2fc2663f ggl::GLDevice::createRenderer() + 110
8 VectorKit 0x2fb46c0f -[MDDisplayLayer _createGLLayer] + 166
9 VectorKit 0x2fb469af -[MDDisplayLayer init] + 70
10 VectorKit 0x2f8763b7 -[VKMapView initWithGlobe:shouldRasterize:inBackground:] + 486
11 MapKit 0x25f4937f -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 362
12 MapKit 0x25f7b14b -[MKMapView _commonInitFromIB:gestureRecognizerHostView:showsAttribution:] + 982
13 MapKit 0x25f7bc4d -[MKMapView initWithCoder:] + 128
14 AppName 0x000ce410 @objc AppName.CustomeMap.init (AppName.CustomeMap.Type)(coder : ObjectiveC.NSCoder) -> AppName.CustomeMap (CustomeMap.swift)
15 UIKit 0x280f6611 -[UIClassSwapper initWithCoder:] + 192
16 UIKit 0x281bd6ef UINibDecoderDecodeObjectForValue + 850
17 UIKit 0x281bd38f -[UINibDecoder decodeObjectForKey:] + 334
18 UIKit 0x280f6253 -[UIRuntimeConnection initWithCoder:] + 150
19 UIKit 0x281bd6ef UINibDecoderDecodeObjectForValue + 850
20 UIKit 0x281bd645 UINibDecoderDecodeObjectForValue + 680
21 UIKit 0x281bd38f -[UINibDecoder decodeObjectForKey:] + 334
22 UIKit 0x280f593f -[UINib instantiateWithOwner:options:] + 958
23 UIKit 0x28014077 -[UIViewController _loadViewFromNibNamed:bundle:] + 238
24 UIKit 0x27e52e99 -[UIViewController loadView] + 92
25 UIKit 0x27d370ed -[UIViewController loadViewIfRequired] + 68
26 UIKit 0x27de0ed5 -[UINavigationController _layoutViewController:] + 32
27 UIKit 0x27de0dfd -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228
28 UIKit 0x27de0393 -[UINavigationController _startTransition:fromViewController:toViewController:] + 74
29 UIKit 0x27de00c3 -[UINavigationController _startDeferredTransitionIfNeeded:] + 578
30 UIKit 0x27ddfe2d -[UINavigationController __viewWillLayoutSubviews] + 44
31 UIKit 0x27ddfdc1 -[UILayoutContainerView layoutSubviews] + 184
32 UIKit 0x27d347ff -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514
33 QuartzCore 0x2775a835 -[CALayer layoutSublayers] + 136
34 QuartzCore 0x2775620d CA::Layer::layout_if_needed(CA::Transaction*) + 360
35 QuartzCore 0x27756095 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
36 QuartzCore 0x27755a71 CA::Context::commit_transaction(CA::Transaction*) + 224
37 QuartzCore 0x27755875 CA::Transaction::commit() + 324
38 UIKit 0x27d2cc91 _afterCACommitHandler + 132
39 CoreFoundation 0x247e0ffd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
40 CoreFoundation 0x247de6bb __CFRunLoopDoObservers + 278
41 CoreFoundation 0x247deac3 __CFRunLoopRun + 914
42 CoreFoundation 0x2472c3b1 CFRunLoopRunSpecific + 476
43 CoreFoundation 0x2472c1c3 CFRunLoopRunInMode + 106
44 GraphicsServices 0x2bd59201 GSEventRunModal + 136
45 UIKit 0x27d9643d UIApplicationMain + 1440
46 AppName 0x000c1d68 main (AppDelegate.swift:17)
删除了子类化概念,只创建了一个 View 并添加了 MKMapView 作为 subview 。但现在我看到了以下崩溃
Crash log
Thread : Crashed: com.apple.main-thread
0 libGPUSupportMercury.dylib 0x2fc468fe gpus_ReturnNotPermittedKillClient
1 libGPUSupportMercury.dylib 0x2fc473cb gpusSubmitDataBuffers
2 libGPUSupportMercury.dylib 0x2fc47249 gldCreateContext
3 GLEngine 0x2b87393b gliCreateContextWithShared
4 OpenGLES 0x2b94fab3 -[EAGLContext initWithAPI:properties:] + 406
5 OpenGLES 0x2b94f86f -[EAGLContext initWithAPI:sharedWithCompute:] + 142
6 VectorKit 0x33ffde8b ggl::OESContext::OESContext(ggl::GLDevice*, std::__1::shared_ptr<ggl::OESSharegroup>) + 530
7 VectorKit 0x33ff6e77 ggl::GLDevice::createRenderer() + 110
8 VectorKit 0x33f1399b -[MDDisplayLayer _createGLLayer] + 166
9 VectorKit 0x33f1373b -[MDDisplayLayer init] + 70
10 VectorKit 0x33c3eae3 -[VKMapView initWithGlobe:shouldRasterize:inBackground:] + 486
11 MapKit 0x2a6586d7 -[MKBasicMapView initWithFrame:andGlobe:shouldRasterize:] + 362
12 MapKit 0x2a68a67f -[MKMapView _commonInitFromIB:gestureRecognizerHostView:showsAttribution:] + 1018
13 MapKit 0x2a676b83 -[MKMapView initWithFrame:] + 130
14 UIKit 0x2c44df19 -[UIView init] + 44
15 AppName 0x000f7598 @!objc ObjectiveC.MKMapView.init (ObjectiveC.MKMapView.Type)() -> ObjectiveC.MKMapView (CustomeMap.swift)
16 AppName 0x000f4f1c ObjectiveC.MKMapView.__allocating_init (ObjectiveC.MKMapView.Type)() -> ObjectiveC.MKMapView (CustomeMap.swift)
17 AppName 0x000ef614 AppName.CustomeMap.awakeFromNib (AppName.CustomeMap)() -> () (CustomeMap.swift:31)
18 AppName 0x000f06ec @objc AppName.CustomeMap.awakeFromNib (AppName.CustomeMap)() -> () (CustomeMap.swift)
19 UIKit 0x2c7ee561 -[UINib instantiateWithOwner:options:] + 1680
20 UIKit 0x2c70d303 -[UIViewController _loadViewFromNibNamed:bundle:] + 238
21 UIKit 0x2c54c805 -[UIViewController loadView] + 92
22 UIKit 0x2c430af9 -[UIViewController loadViewIfRequired] + 68
23 UIKit 0x2c4dab75 -[UINavigationController _layoutViewController:] + 32
24 UIKit 0x2c4daa9d -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 228
25 UIKit 0x2c4da033 -[UINavigationController _startTransition:fromViewController:toViewController:] + 74
26 UIKit 0x2c4d9d63 -[UINavigationController _startDeferredTransitionIfNeeded:] + 578
27 UIKit 0x2c4d9acd -[UINavigationController __viewWillLayoutSubviews] + 44
28 UIKit 0x2c4d9a61 -[UILayoutContainerView layoutSubviews] + 184
29 UIKit 0x2c42e24f -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 514
30 QuartzCore 0x2be56a0d -[CALayer layoutSublayers] + 136
31 QuartzCore 0x2be523e5 CA::Layer::layout_if_needed(CA::Transaction*) + 360
32 QuartzCore 0x2be5226d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
33 QuartzCore 0x2be51c51 CA::Context::commit_transaction(CA::Transaction*) + 224
34 QuartzCore 0x2be51a55 CA::Transaction::commit() + 324
35 UIKit 0x2c4266e5 _afterCACommitHandler + 132
36 CoreFoundation 0x28f34d95 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
37 CoreFoundation 0x28f32453 __CFRunLoopDoObservers + 278
38 CoreFoundation 0x28f3285b __CFRunLoopRun + 914
39 CoreFoundation 0x28e803c1 CFRunLoopRunSpecific + 476
40 CoreFoundation 0x28e801d3 CFRunLoopRunInMode + 106
41 GraphicsServices 0x302550a9 GSEventRunModal + 136
42 UIKit 0x2c48ffa1 UIApplicationMain + 1440
43 AppName 0x000eb500 main (AppDelegate.swift:21)
44 libdyld.dylib 0x36fa6aaf start + 2
请有人帮忙找到我在这里丢失的东西。
最佳答案
看起来子类与原始初始化方法混淆了。 MKMapView 的文档说你不应该子类化,而应该使用委托(delegate)来处理你需要的一切。
Although you should not subclass the MKMapView class itself, you can get information about the map view’s behavior by providing a delegate object.
我建议您创建一个自定义的 UIView 子类,其中包含一个 MKMapView 并充当其委托(delegate)。这是我尝试解决此问题的第一步。
关于swift - 自定义 map View 在 initWithCoder 中 swift 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30116179/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c