在我的應用程序中,我有一個textfield
窗體,我想從日期選擇器填充,我已將日期選擇器分配爲文本框的輸入視圖,並且使用datePickerValueChanged
func更改文本框的文本被改變。我的問題是,在應用程序關閉點擊數據選擇器時,整個應用程序與UIDatePicker崩潰的應用程序
崩潰
任何想法「目標類型NSException未捕獲的異常終止」?這裏是我的代碼:
@IBOutlet var startDatePickerField: UITextField!
override func viewDidLoad() {
let startDatePicker:UIDatePicker = UIDatePicker()
startDatePicker.datePickerMode = UIDatePickerMode.dateAndTime
startDatePickerField.inputView = startDatePicker
startDatePicker.addTarget(self, action: #selector(popoverTableViewController.datePickerValueChanged(_:)), for: UIControlEvents.valueChanged)
}
func datePickerValueChanged(_ sender: UIDatePicker) {
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = DateFormatter.Style.long
dateFormatter.timeStyle = DateFormatter.Style.short
startDatePickerField.text = dateFormatter.string(from: sender.date)
}
這是所有包含在類視圖控制器「popoverTableViewController」。謝謝!
下面是從日誌中的故障報告:
2016年7月28日12:50:00.956 ClockIn_v2 [5935:2049267] - [ClockIn_v2.popoverTableViewController startDateDidBegin:]:無法識別的選擇發送到實例0x7ff571c10720 2016年7月28日12 :50:00.961 ClockIn_v2 [5935:2049267] *終止應用程序由於 未捕獲的異常 'NSInvalidArgumentException',原因: 「 - [ClockIn_v2.popoverTableViewController startDateDidBegin:]: 無法識別的選擇發送到實例0x7ff571c10720 ' *第一次拋出調用堆棧:(0 CoreFoundation 0x000000010fe5986b exceptionPreprocess + 171 1 libobjc.A。dylib
0x000000010f4b124e objc_exception_throw + 48 2的CoreFoundation
0x000000010fec7904 - [NSObject的(NSObject的)doesNotRecognizeSelector:] + 132 3的CoreFoundation 0x000000010fddfed5 ___forwarding_ + 1013 4的CoreFoundation 0x000000010fddfa58 _CF_forwarding_prep_0 + 120 5的UIKit
0x000000011027aaf0 - [UIApplication的sendAction:至:從:forEvent:] + 83 6的UIKit 0x00000001103fda69 - [UIControl sendAction:至:forEvent:] + 67 7的UIKit 0x00000001103fdd82 - [UIControl _sendActionsForEvents:withEvent:方法] + 444 8的UIKit 0x0000000110d5b196 - [的UITextField _resignFirstResponder] + 297 9 UIK它0x000000011048d780 - [UIResponder _finishResignFirstResponder] + 286 10的UIKit 0x0000000110d5af94 - [的UITextField _finishResignFirstResponder] + 49 11的UIKit 0x000000011048d82f - [UIResponder resignFirstResponder] + 140 12 的UIKit 0x0000000110d5ae63 - [的UITextField resignFirstResponder] + 136 13的UIKit
0x000000011048d4bf - [ UIResponder becomeFirstResponder] + 358 14 的UIKit 0x0000000110328dae - [UIView的(層次)becomeFirstResponder] + 138 15的UIKit 0x0000000110d59d2e - [的UITextField becomeFirstResponder] + 51 16的UIKit 0x00000001107af37b - [UITextInteractionAssistant(UITextInteractionAssistant_Internal)setFirstResponderIfNecessary] + 206 17 UIK它
0x00000001107b2b46 - [UITextInteractionAssistant(UITextInteractionAssistant_Internal)oneFingerTap:] + 3823 18的UIKit
0x00000001107a081d - [UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57 19的UIKit 0x00000001107a85b4 _UIGestureRecognizerSendTargetActions + 109 20 的UIKit 0x00000001107a613b _UIGestureRecognizerSendActions + 540 21的UIKit 0x00000001107a539d - [UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1177 22的UIKit 0x00000001107911f2 _UIGestureEnvironmentUpdate + 1013 23的UIKit
0x0000000110790db5 - [UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlo放:] + 521 24的UIKit 0x000000011078ff2c - [UIGestureEnvironment _updateGesturesForEvent:窗口:] + 286 25的UIKit 0x00000001102e945c - [一個UIWindow的SendEvent:] + 3989 26的UIKit
0x00000001102967a5 - [UIApplication的的SendEvent:] + 281 27的UIKit
0x0000000110a632c3 dispatchPreprocessedEventFromEventQueue + 3303 28的UIKit 0x0000000110a5be75 __handleEventQueue + 4879 29的CoreFoundation 0x000000010fdff5d1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 30的CoreFoundation 0x000000010fde485c __CFRunLoopDoSources0 + 556 31的CoreFoundation 0x000000010fde3d46 __CFRunLoopRun + 918 32的CoreFoundation
0x000000010fde3754 CFRunLoopRunSpecific + 420 33 GraphicsServices
0x0000000114629a71 GSEventRunModal + 161 34的UIKit
0x0000000110278e9c UIApplicationMain + 159 35 ClockIn_v2
0x000000010eec96df主+ 111 36 libdyld.dylib
0x00000001136a968d啓動+ 1)的libC++ ABI。dylib:與類型NSException(LLDB)的 未捕獲的異常終止
出租車你顯示完整的崩潰報告 –
我添加了崩潰的日誌內容到帖子,這是你的意思嗎? – user2662468
你的'popoverTableViewController'被正確初始化了嗎?如果包含選擇器的實例爲零,則會引發異常。 – NSGangster