ios - 在 Swift 中测试我的应用程序时出错

标签 ios swift

我是所有编码方面的新手,我正忙于用 Swift 构建应用程序。我正在制作一个按钮,当它被按下时,它应该转到下一页,该页面具有 AVCam 的相机功能。第一页打开得很好,当我按下按钮转到相机 View 页面时,应用程序崩溃了。

进入相机查看页面的按钮代码如下:

@IBAction func goToApp(sender : AnyObject) {
    let AVCamViewController = self.storyboard.instantiateViewControllerWithIdentifier("AVCamViewController") as UIImagePickerController
    self.navigationController.pushViewController(AVCamViewController, animated: true)
}

当我在手机上尝试时,应用程序崩溃后的错误如下:

libswift_stdlib_core.dylib`swift_dynamicCastClassUnconditional:
0x1001f32c4:  stp    x20, x19, [sp, #-32]!
0x1001f32c8:  stp    fp, lr, [sp, #16]
0x1001f32cc:  add    fp, sp, #16
0x1001f32d0:  mov    x20, x1
0x1001f32d4:  mov    x19, x0
0x1001f32d8:  ldrb   w8, [x20, #32]
0x1001f32dc:  tbz    w8, #0, 0x2c
0x1001f32e0:  tbnz   w19, #0, 0x4c
0x1001f32e4:  cmp    x19, #1
0x1001f32e8:  b.lt   0x44
0x1001f32ec:  mov    x0, x19
0x1001f32f0:  bl     0x10f24
0x1001f32f4:  cmp    x0, x20
0x1001f32f8:  b.eq   0x20
0x1001f32fc:  ldr    x0, [x0, #8]
0x1001f3300:  cbnz   x0, 0xfffffffffffffff4
0x1001f3304:  b      0x28
0x1001f3308:  mov    x0, x19
0x1001f330c:  mov    x1, x20
0x1001f3310:  bl     0xc1ec
0x1001f3314:  mov    x19, x0
0x1001f3318:  cbz    x19, 0x14
0x1001f331c:  mov    x0, x19
0x1001f3320:  ldp    fp, lr, [sp, #16]
0x1001f3324:  ldp    x20, x19, [sp], #32
0x1001f3328:  ret    
0x1001f332c:  brk    #1
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1001f332c)

如果我在模拟器上运行它,错误如下:

libswift_stdlib_core.dylib`swift_dynamicCastClassUnconditional:
0x1001c2f90:  pushq  %rbp
0x1001c2f91:  movq   %rsp, %rbp
0x1001c2f94:  pushq  %r14
0x1001c2f96:  pushq  %rbx
0x1001c2f97:  movq   %rsi, %rbx
0x1001c2f9a:  movq   %rdi, %r14
0x1001c2f9d:  testb  $0x1, 0x20(%rbx)
0x1001c2fa1:  je     0x1001c2fd0               ; swift_dynamicCastClassUnconditional + 64
0x1001c2fa3:  testb  $0x1, %r14b
0x1001c2fa7:  jne    0x1001c2feb               ; swift_dynamicCastClassUnconditional + 91
0x1001c2fa9:  testq  %r14, %r14
0x1001c2fac:  jle    0x1001c2feb               ; swift_dynamicCastClassUnconditional + 91
0x1001c2fae:  movq   %r14, %rdi
0x1001c2fb1:  callq  0x1001d5194               ; symbol stub for: object_getClass
0x1001c2fb6:  nopw   %cs:(%rax,%rax)
0x1001c2fc0:  cmpq   %rbx, %rax
0x1001c2fc3:  je     0x1001c2fde               ; swift_dynamicCastClassUnconditional + 78
0x1001c2fc5:  movq   0x8(%rax), %rax
0x1001c2fc9:  testq  %rax, %rax
0x1001c2fcc:  jne    0x1001c2fc0               ; swift_dynamicCastClassUnconditional + 48
0x1001c2fce:  jmp    0x1001c2feb               ; swift_dynamicCastClassUnconditional + 91
0x1001c2fd0:  movq   %r14, %rdi
0x1001c2fd3:  movq   %rbx, %rsi
0x1001c2fd6:  callq  0x1001cfa90               ; swift_dynamicCastObjCClass
0x1001c2fdb:  movq   %rax, %r14
0x1001c2fde:  testq  %r14, %r14
0x1001c2fe1:  je     0x1001c2feb               ; swift_dynamicCastClassUnconditional + 91
0x1001c2fe3:  movq   %r14, %rax
0x1001c2fe6:  popq   %rbx
0x1001c2fe7:  popq   %r14
0x1001c2fe9:  popq   %rbp
0x1001c2fea:  retq   
0x1001c2feb:  leaq   0x16067(%rip), %rax       ; "Swift dynamic cast failed"
0x1001c2ff2:  movq   %rax, 0x77c67(%rip)       ; gCRAnnotations + 8
0x1001c2ff9:  int3   
0x1001c2ffa:  nopw   (%rax,%rax)
Thread 1: EXC_BREAKPOINT (code=EXC_1386_BPT, subcode=0x0)

知道错误可能在哪里吗?

最佳答案

看起来 Controller 不是预期的类型,导致转换错误。尝试将第一行拆分为

@IBAction func goToApp(sender : AnyObject) {
    let controller = self.storyboard.instantiateViewControllerWithIdentifier("AVCamViewController")
    let AVCamViewController = controller as? UIImagePickerController
    self.navigationController.pushViewController(AVCamViewController!, animated: true)
}

这应该可以更容易地查看它是否设法通过该标识符实例化 Controller ,如果是这样,它是否是预期的类型。

关于ios - 在 Swift 中测试我的应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25873292/

相关文章:

iOS 区域监控,设备重启后位置不会发生重大变化

ios - Swift 生成保护声明时出错

ios - papervision 3d对于iOS的播放速度极慢

ios - 是否有适用于 Facebook 好友的人物选择器 View Controller ?

swift - 通用 Controller 内的通用 Swift 协议(protocol)

ios - 无法将值写入 firebase Swift 3

ios - 无法在 NSObject Xcode 中使用 UIView

ios - 暂停的音频开始在 applicationWillEnterForeground : 上自动播放

ios - 在 iOS 中如何知道哪个 ibeacon 正在为它输入一些信息?

swift - 如何设置自动布局以使图像占据全屏?