2015-10-14 58 views
0

类的ViewController:UIViewController的{致命错误:意外地发现零而展开的可选值Mapkit

@IBOutlet var Map: MKMapView! 


    override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    let location = CLLocationCoordinate2DMake(41.7, 2.1667) 

    let span = MKCoordinateSpanMake(0.2, 0.2) 
    let region = MKCoordinateRegion(center: location, span: span) 

Map.setRegion(region, animated: true) 



let annotation = MKPointAnnotation() 

annotation.coordinate=(location) 

    annotation.title = "Sant Feliu de Codines" 

    Map.addAnnotation(annotation) 

出现的错误是:线程1:EXC_BAD_INTRUCTION(代码= EXC_1386_INVOP,子码=为0x0)

libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) ->(): 
0x2a2d0c <+0>: push {r4, r5, r6, r7, lr} 
0x2a2d10 <+4>: add r7, sp, #12 
0x2a2d14 <+8>: push {r8, r10, r11} 
0x2a2d18 <+12>: sub sp, sp, #40 
0x2a2d1c <+16>: bfc sp, #0, #3 
0x2a2d20 <+20>: mov r11, r3 
0x2a2d24 <+24>: mov r6, r0 
0x2a2d28 <+28>: ldr r0, [r7, #0xc] 
0x2a2d2c <+32>: ldr r3, [r7, #0x8] 
0x2a2d30 <+36>: tst r2, #1 
0x2a2d34 <+40>: bne 0x2a2d58     ; <+76> 
0x2a2d38 <+44>: cmp r1, #0 
0x2a2d3c <+48>: blt 0x2a2d80     ; <+116> 
0x2a2d40 <+52>: str r0, [sp] 
0x2a2d44 <+56>: add r1, r6, r1 
0x2a2d48 <+60>: mov r0, r6 
0x2a2d4c <+64>: mov r2, r11 
0x2a2d50 <+68>: bl  0x2e7088 
; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) ->()).(closure #2) 

- > 0x2a2d54 < +72>:陷阱

感谢您的帮助!

回答

0

好一件事,你需要改变的是:

annotation.coordinate=(location) 

到:

annotation.coordinate = location 

否则,请确认您的IBOutlet中正确挂接和你在Interface Builder中没有其他错误。

+0

我得到的唯一的错误是这一个,我找不到为什么当我尝试启动应用程序时出现错误。我认为接口生成器的其余部分没有任何其他错误。 –

+0

您的问题是两件事之一:您的IBOutlet未正确连接到界面构建器中的视图,或者您的界面构建器中的视图不是类MKMapView。基本上,发生的事情是Map在viewDidLoad中的值为nil,这会在setRegion行上触发您的错误。 –

相关问题