【发布时间】:2017-09-12 07:53:11
【问题描述】:
我收到了以下崩溃报告,但我不明白这个问题。第 487 行指向检查委托中的 pickerView 是否是特定变量。
Crashed: com.apple.main-thread
0 App 0x1001c5208 specialized NewCorrectiveVC.pickerView(UIPickerView, didSelectRow : Int, inComponent : Int) -> () (NewCorrectiveVC.swift:487)
1 App 0x1001c2028 @objc NewCorrectiveVC.pickerView(UIPickerView, didSelectRow : Int, inComponent : Int) -> () (NewCorrectiveVC.swift)
2 UIKit 0x197a83154 -[UIPickerView _sendSelectionChangedForComponent:notify:] + 116
3 UIKit 0x197a8338c -[UIPickerView _sendSelectionChangedFromTable:notify:] + 344
4 UIKit 0x197fb0424 -[UIPickerTableView _scrollingFinished] + 188
5 UIKit 0x197fb05fc -[UIPickerTableView scrollViewDidEndDecelerating:] + 28
6 UIKit 0x197b216ac -[UIScrollView(UIScrollViewInternal) _scrollViewDidEndDeceleratingForDelegate] + 132
7 UIKit 0x1979b6db0 -[UIScrollView(UIScrollViewInternal) _stopScrollDecelerationNotify:] + 332
8 UIKit 0x1979b68ec -[UIScrollView _smoothScrollWithUpdateTime:] + 2356
9 QuartzCore 0x194bc01bc CA::Display::DisplayLinkItem::dispatch(unsigned long long) + 44
10 QuartzCore 0x194bc0068 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 444
11 IOKit 0x191c27138 IODispatchCalloutFromCFMessage + 372
12 CoreFoundation 0x19195056c __CFMachPortPerform + 180
13 CoreFoundation 0x191968934 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
14 CoreFoundation 0x1919680e8 __CFRunLoopDoSource1 + 436
15 CoreFoundation 0x191965bcc __CFRunLoopRun + 1840
16 CoreFoundation 0x191894048 CFRunLoopRunSpecific + 444
17 GraphicsServices 0x19331a198 GSEventRunModal + 180
18 UIKit 0x1978792fc -[UIApplication _run] + 684
19 UIKit 0x197874034 UIApplicationMain + 208
20 App 0x100173d04 main (AppDelegate.swift:22)
21 libdispatch.dylib 0x1908785b8 (Missing)
代码:
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if pickerView == assignedTo
{
if employees.count > 0 {
selectedEmp = employees[row].employeeId
}
}
else if pickerView == category \\this is line 487
{
if categories.count > 0 {
selectedCat = categories[row].wocategoryId
}
}
}
编辑:
不确定以下是否相关,但我确实有观察者链接到我的 pickerViews:
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.longPressed))
assignedTo.addGestureRecognizer(longPressRecognizer)
let catLongPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.catLongPressed))
category.addGestureRecognizer(catLongPressRecognizer)
self.hideKeyboardWhenTappedAround()
self.scroll.keyboardDismissMode = .interactive
仅供参考:
public func hideKeyboardWhenTappedAround() {
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
}
【问题讨论】:
-
能否分享一下您遇到了什么异常,这对我们更有帮助。
-
@AshokPolu 在 crashlytics 我看到 EXC_BREAKPOINT 然后上面粘贴了 sn-p
-
在 487 行下断点,调试应用程序,可能类别为 nil。
-
在 swift @AshokPolu 中与
nil比较是完全可能的 -
这种情况的任何部分(修改数组或调用 UIKit 方法)发生在非主线程上是最常见的原因。另一个是更改数组而不通知选择器视图事情已经改变(例如调用
reloadAllComponents)。但请参阅下面的答案
标签: ios arrays swift uigesturerecognizer uipickerview