【发布时间】:2018-07-17 17:30:51
【问题描述】:
我遇到了 EXC_Breakpoint 崩溃,这表明有一个 nil 变量被解包?
它所指向的代码行是let obHeight的定义:
if let qs = Helper_Question.getSection(sid: self.sections[0].sid) {
let obEnabled = Helper_Type.getId(id: tid)?.enableObservation == 1
for q in qs {
let ans = Helper_Answer.getQuestion(aid: selectedAid!, qid: q.Id)
var baseHeight : CGFloat = 300
switch(q.qtype){
case Constants.DEFAULT:
let obHeight : CGFloat = (obEnabled || ans?.comment != "" || (ans?.answer == "1" && q.hasChildren == 0) || (ans?.answer == "2" && q.hasChildren == 0)) && ans?._na == 0 ? 40 : 0
....
}
}
}
我使用的是? 而不是强行展开,所以我认为这不是问题所在?这份崩溃报告是今天发布的,但我无法在任何设备上重现它。除了nil 变量之外,还有什么其他原因会导致EXC_Breakpoint 崩溃?此代码在表格视图单元格中的按钮单击操作上调用,并使用委托调用此代码以在呈现 splitviewcontroller 之前执行一些计算。 selectedAid 来自按钮的可访问性标识符,我始终在单元格中为行设置该标识符。它不是零
崩溃日志:
Crashed: com.apple.main-thread
0 AppName 0x100664b30 specialized AuditVC.editBtnTapped(cell : PendingAuditTVC) -> () (AuditVC.swift:294)
1 AppName 0x10065fa68 AuditVCAppNamePendingAuditCellDelegate (AuditVC.swift)
2 AppName 0x100717468 PendingAuditTVC.editTapped(Any) -> () (PendingAuditTVC.swift:41)
3 AppName 0x100717648 @objc PendingAuditTVC.editTapped(Any) -> () + 4302730824
4 UIKit 0x1907c6010 -[UIApplication sendAction:to:from:forEvent:] + 96
5 UIKit 0x1907c5f90 -[UIControl sendAction:to:forEvent:] + 80
6 UIKit 0x1907b0504 -[UIControl _sendActionsForEvents:withEvent:] + 440
7 UIKit 0x1907c5874 -[UIControl touchesEnded:withEvent:] + 576
8 UIKit 0x190d5a550 _UIGestureEnvironmentSortAndSendDelayedTouches + 4280
9 UIKit 0x190d5689c _UIGestureEnvironmentUpdate + 1128
10 UIKit 0x190d563e0 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
11 UIKit 0x190d5568c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 268
12 UIKit 0x1907c070c -[UIWindow sendEvent:] + 3164
13 UIKit 0x19079133c -[UIApplication sendEvent:] + 340
14 UIKit 0x190f8b014 __dispatchPreprocessedEventFromEventQueue + 2400
15 UIKit 0x190f85770 __handleEventQueue + 4268
16 UIKit 0x190f85b9c __handleHIDEventFetcherDrain + 148
17 CoreFoundation 0x18a61542c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
18 CoreFoundation 0x18a614d9c __CFRunLoopDoSources0 + 540
19 CoreFoundation 0x18a6129a8 __CFRunLoopRun + 744
20 CoreFoundation 0x18a542da4 CFRunLoopRunSpecific + 424
21 GraphicsServices 0x18bfac074 GSEventRunModal + 100
22 UIKit 0x1907f6058 UIApplicationMain + 208
23 AppName 0x100044590 main (AppDelegate.swift:23)
24 libdyld.dylib 0x18955159c start + 4
更新
open class Question
{
open var Id : Int = 0
open var sectionid : Int = 0
open var question : String = ""
open var hasChildren : Int = 0
open var qtype : Int = 0
open var defaultValue : String = ""
}
public class UP_IA_Answer_m : EVObject {
public var localId : String = ""
public var aid : String = ""
public var sid : Int = 0
public var qid : Int = 0
public var answer : String = ""
public var comment : String = ""
public var hasChildren : Int = 0
public var _na : Int = 0
}
【问题讨论】:
-
与您的问题无关,但
? true : false是不必要的,省略。 -
@the4kman 完成。对问题没有想法?我与一位用户发生了 4 次崩溃。
-
你确定
q不为零吗? -
查看
Question和Answer的模型会很有帮助,我认为这是模型名称... -
@the4kman q 不是 nil,不。只要 qs 返回值,这些值都不是 nil。
标签: swift uitableview exception delegates crashlytics