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>:陷阱
感謝您的幫助!
我得到的唯一的錯誤是這一個,我找不到爲什麼當我嘗試啓動應用程序時出現錯誤。我認爲接口生成器的其餘部分沒有任何其他錯誤。 –
您的問題是兩件事之一:您的IBOutlet未正確連接到界面構建器中的視圖,或者您的界面構建器中的視圖不是類MKMapView。基本上,發生的事情是Map在viewDidLoad中的值爲nil,這會在setRegion行上觸發您的錯誤。 –