ScrollView,TextField和pickerview麻烦

时间:2015-05-20 11:17:57

标签: swift uiscrollview uitextfield uipickerview

我的问题是,当我运行项目并单击第一个文本字段(其他文件现在为空)时,应用程序崩溃并出现此错误:

  

由于未捕获的异常'UIViewControllerHierarchyInconsistency'而终止应用程序,原因:'子视图控制器:<UICompatibilityInputViewController: 0x12dd4c600>应该有父视图控制器:<Sai_Service.ServiceAppointment: 0x12dd151a0>但请求父级是:<UIInputWindowController: 0x12e00b600>'。

这是我的代码:

import UIKit

class ServiceAppointment: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var ScrollView: UIScrollView!

    @IBOutlet weak var pickerView: UIPickerView!

    @IBOutlet weak var StateField: UITextField!

    @IBOutlet weak var CityField: UITextField!

    @IBOutlet weak var VehRegNumberField: UITextField!

    @IBOutlet weak var LocationField: UITextField!

    @IBOutlet weak var CurrentKmsField: UITextField!

    @IBOutlet weak var apptDateFIeld: UITextField!

    @IBOutlet weak var apptTypeField: UITextField!

    @IBOutlet weak var pickupField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        ScrollView.contentSize.height = 1000
        pickerView.hidden = true;
        StateField.text = States[0]
        self.pickerView.dataSource = self;
        self.pickerView.delegate = self;
        self.StateField.inputView = pickerView         
            }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    var States = ["Italy","United States","UK","France"]

    //MARK: - Delegates and data sources
    //MARK: Data Sources
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return States.count
    }

    //MARK: Delegates
    func pickerView2(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        return States[row]
    }

    func pickerView3(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        StateField.text = States[row]
        pickerView.hidden = true;
    }
    func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
        pickerView.hidden = false
        return false
    }
}

我认为这是多视图的问题,所以我在viewDidLoad中写道:

self.StateField.removeFromSuperView() 

然后所有的ScrollViews显然都消失了。

如何使这项工作成为可能,当我按下文本字段时,会出现选择器视图?

0 个答案:

没有答案