UIDatePicker崩溃的应用程序 [英] UIDatePicker crashing application

查看:117
本文介绍了UIDatePicker崩溃的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我有一个要从日期选择器填充的textfield表单,我已将日期选择器指定为文本字段的输入视图,并指定了一个datePickerValueChanged func来更改文本字段的文本.选择器已更改.我的问题是,当单击应用程序中的数据选择器时,整个应用程序会因

In my app I have a textfield form that i want populated from a date picker, I have assigned the date picker as the input view for the textfield and a datePickerValueChanged func to change the text of the textfield when the picker is changed. My issue is that when clicking off the data picker in the app, the whole app crashes with

以类型为NSException的未捕获异常终止"

'terminating with uncaught exception of type NSException'

有什么想法吗?这是我的代码:

any ideas? Here is my code:

@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"的类中.谢谢!

This is all contained in the class for the view controller "popoverTableViewController". Thanks!

这是日志中的崩溃报告:

Here is the crash report from log:

2016-07-28 12:50:00.956 ClockIn_v2 [5935:2049267] -[ClockIn_v2.popoverTableViewController startDateDidBegin:]:无法识别的选择器已发送到实例0x7ff571c10720 2016-07-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)didNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010fddfed5 ___ forwarding _
+ 1013 4 CoreFoundation 0x000000010fddfa58 _CF_forwarding_prep_0 + 120 5 UIKit
0x000000011027aaf0-[UIApplication sendAction:to:from:forEvent:] + 83 6 UIKit 0x00000001103fda69 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x00000001103fdd82-[UIControl _sendActionsForEvents:withEvent:] + 444 8个UIKit 0x0000000110d5b196 -[UITextField _resignFirstResponder] + 297 9 UIKit 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成为FirstResponder] + 358 14 UIKit 0x0000000110328dae -[UIView(Hierarchy)成为FirstResponder] + 138 15 UIKit 0x0000000110d59d2e-[UITextField成为FirstResponder] + 51 16 UIKit 0x00000001107af37b -[UITextInteractionAssistant(UITextInteractionAssistant_Internal)setFirstResponderIfNecessary] + 206 17 UIKit
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:usingBlock:] + 521 24 UIKit 0x000000011078ff2c-[UIGestureEnvironment _updateGesturesForEvent:window:] + 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 main + 111 36 libdyld.dylib
0x00000001136a968d start + 1)libc ++ abi.dylib:终止于 类型为NSException(lldb)的未捕获异常

2016-07-28 12:50:00.956 ClockIn_v2[5935:2049267] -[ClockIn_v2.popoverTableViewController startDateDidBegin:]: unrecognized selector sent to instance 0x7ff571c10720 2016-07-28 12:50:00.961 ClockIn_v2[5935:2049267] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ClockIn_v2.popoverTableViewController startDateDidBegin:]: unrecognized selector sent to instance 0x7ff571c10720' * First throw call stack: ( 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:to:from:forEvent:] + 83 6 UIKit 0x00000001103fda69 -[UIControl sendAction:to:forEvent:] + 67 7 UIKit 0x00000001103fdd82 -[UIControl _sendActionsForEvents:withEvent:] + 444 8 UIKit 0x0000000110d5b196 -[UITextField _resignFirstResponder] + 297 9 UIKit 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(Hierarchy) becomeFirstResponder] + 138 15 UIKit 0x0000000110d59d2e -[UITextField becomeFirstResponder] + 51 16 UIKit 0x00000001107af37b -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 206 17 UIKit
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:usingBlock:] + 521 24 UIKit 0x000000011078ff2c -[UIGestureEnvironment _updateGesturesForEvent:window:] + 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 main + 111 36 libdyld.dylib
0x00000001136a968d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

推荐答案

而不是使用

startDatePicker.addTarget(self, action:  #selector(popoverTableViewController.datePickerValueChanged(_:)), for: UIControlEvents.valueChanged)  

在助理"编辑器中将其打开,一部分打开情节提要,右键单击日期选择器,在事件列表中,单击值已更改"(当您将鼠标悬停在前面有一个空洞)并将其扩展到您的"popoverTableViewController.swift"文件.

Open it in Assistant editor, open storyboard in one part, right click on your date picker, in the list of events, click on "Value Changed" (it will show a little '+' sign when you will hover upon the empty hole in front of it) and extend it to your "popoverTableViewController.swift" file.

这篇关于UIDatePicker崩溃的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆