2017-09-29 10 views
0

피커가 내 텍스트 필드를 클릭하면 보여주는 프로그램을 만들었고 툴바에서 "완료"또는 "취소"버튼을 클릭하면 프로그램을 닫으려고합니다.피커를 닫으려고 할 때 오류가 발생했습니다

어디서 잘못되었는지는 알 수 없습니다. 그것은 말합니다 비록

"2017-09-28 20 : 45 : 27.877897-0600 project1 [51296 : 5112470] [LayoutConstraints] 동시에 제약 조건을 만족시킬 수 없습니다."

내 제약의 모든

여기

내 코드입니다 .. 잘 기압 노력하고 있습니다 :

@IBOutlet weak var textField1: UITextField! 

override func viewDidLoad() { 
    super.viewDidLoad() 


    let picker: UIPickerView 

    picker = UIPickerView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 300)) 
    picker.backgroundColor = .white 

    picker.showsSelectionIndicator = true 
    picker.delegate = self 
    picker.dataSource = self 

    let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 40)) 
    toolBar.barStyle = UIBarStyle.default 
    toolBar.isTranslucent = true 
    toolBar.tintColor = .black 

    let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: 
     Selector(("donePicker"))) 
    let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
    let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: Selector(("donePicker"))) 
    ) 

    toolBar.setItems([cancelButton, spaceButton, doneButton], animated: true) 
    toolBar.isUserInteractionEnabled = true 

    let bgView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 250 + toolBar.frame.size.height)) 
    print(picker.frame.size.height, toolBar.frame.size.height, bgView.frame.size.height) 


    bgView.addSubview(picker) 
    bgView.addSubview(toolBar) 
    textField1.inputView = bgView 
} 

func donePicker() { 
    textField1.resignFirstResponder() 
} 

그리고 이것은 나에게 주시는 오류입니다 : 내가 시도

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. 
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 
2017-09-28 20:45:29.253610-0600 project1[51296:5112470] [MC] Lazy loading NSBundle MobileCoreServices.framework 
2017-09-28 20:45:29.255001-0600 project1[51296:5112470] [MC] Loaded MobileCoreServices.framework 
2017-09-28 20:45:29.274235-0600 project1[51296:5112470] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/Andrew/Library/Developer/CoreSimulator/Devices/EE44EDE5-BDF6-4A15-A44B-387E14685DAA/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 
300.0 44.0 294.0 
2017-09-28 20:45:30.401748-0600 project1[51296:5112470] [MC] Reading from private effective user settings. 
2017-09-28 20:45:31.827410-0600 project1[51296:5112470] -[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0 
2017-09-28 20:45:31.835746-0600 project1[51296:5112470] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0' 
*** First throw call stack: 
(
    0 CoreFoundation      0x000000010c8a11cb __exceptionPreprocess + 171 
    1 libobjc.A.dylib      0x000000010a93cf41 objc_exception_throw + 48 
    2 CoreFoundation      0x000000010c921914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 
    3 UIKit        0x000000010d4660bd -[UIResponder doesNotRecognizeSelector:] + 295 
    4 CoreFoundation      0x000000010c824178 ___forwarding___ + 1432 
    5 CoreFoundation      0x000000010c823b58 _CF_forwarding_prep_0 + 120 
    6 UIKit        0x000000010d23f9bd -[UIApplication sendAction:to:from:forEvent:] + 83 
    7 UIKit        0x000000010dc3353f __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 154 
    8 UIKit        0x000000010dc33470 -[_UIButtonBarTargetAction _invoke:forEvent:] + 181 
    9 UIKit        0x000000010d23f9bd -[UIApplication sendAction:to:from:forEvent:] + 83 
    10 UIKit        0x000000010d3b6183 -[UIControl sendAction:to:forEvent:] + 67 
    11 UIKit        0x000000010d3b64a0 -[UIControl _sendActionsForEvents:withEvent:] + 450 
    12 UIKit        0x000000010d3b53cd -[UIControl touchesEnded:withEvent:] + 618 
    13 UIKit        0x000000010d2b3d4f -[UIWindow _sendTouchesForEvent:] + 2807 
    14 UIKit        0x000000010d2b5472 -[UIWindow sendEvent:] + 4124 
    15 UIKit        0x000000010d25a802 -[UIApplication sendEvent:] + 352 
    16 UIKit        0x000000010db8ca50 __dispatchPreprocessedEventFromEventQueue + 2809 
    17 UIKit        0x000000010db8f5b7 __handleEventQueueInternal + 5957 
    18 CoreFoundation      0x000000010c8442b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    19 CoreFoundation      0x000000010c8e3d31 __CFRunLoopDoSource0 + 81 
    20 CoreFoundation      0x000000010c828c19 __CFRunLoopDoSources0 + 185 
    21 CoreFoundation      0x000000010c8281ff __CFRunLoopRun + 1279 
    22 CoreFoundation      0x000000010c827a89 CFRunLoopRunSpecific + 409 
    23 GraphicsServices     0x00000001122ee9c6 GSEventRunModal + 62 
    24 UIKit        0x000000010d23dd30 UIApplicationMain + 159 
    25 UofA Engineering Master    0x0000000109ffa307 main + 55 
    26 libdyld.dylib      0x000000010fbc5d81 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

답변

0

을 다른 방법은 PickerViewtoolbartextField에 표시하는 것입니다. 이 시나리오에 도움이된다면

이 시도 :

let toolBar = UIToolbar() 
toolBar.barStyle = UIBarStyle.default 
toolBar.isTranslucent = true 
toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1) 
toolBar.sizeToFit() 

let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(CalculateViewController.donePicker)) 
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(CalculateViewController.cancelPicker)) 

toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false) 
toolBar.isUserInteractionEnabled = true 

textField1.inputView = pickerView 
textField1.inputAccessoryView = toolBar 
0

당신은 오류 메시지를 볼 수있는 것은 :

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[project1.CalculateViewController donePicker]: unrecognized selector sent to instance 0x7faac1d0fab0' 

스위프트를 들어, 우리는 그와 같은 selector을 정의하지 않습니다 (이 목적이다 C 방식). 당신은 다음과 같이 사용한다 : 오류가 인스턴스에 보낸 인식 할 수없는 선택이다

let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: 
    #selector(donePicker)) 
0

때문에, 당신은 피커가 자산이 할 수 있습니다. viewdidload 방법 중 let picker: UIPickerViewvar picker: UIPickerView?

으로 바꿉니다.
관련 문제