UITextView会引发层次结构不一致

时间:2016-04-13 03:47:02

标签: ios xcode swift uitextview sigabrt

我试图在触摸UITextView时显示一个选择器视图。它工作,但然后它突然崩溃,抛出以下错误(Frete Empresa是项目的名称):

2016-04-13 00:36:31.837 Frete Empresa[8927:361509] *** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<UICompatibilityInputViewController: 0x7af38e80> should have parent view controller:<Frete_Empresa.ViewController: 0x7ae723d0> but requested parent is:<UIInputWindowController: 0x7c227200>'

viewController.swift的代码:

import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

    @IBOutlet weak var txtTipoCaminhao: UITextField!
    @IBOutlet weak var pickerTipoCaminhao: UIPickerView!
    var arrayTipoCaminhao = ["Semileve", "Leve", "Médio", "Semipesado", "Pesado", "Extrapesado"]

    @IBAction func displayPicker(sender: AnyObject) {
        pickerTipoCaminhao.hidden = false
    }


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        pickerTipoCaminhao.delegate = self
        txtTipoCaminhao.inputView = pickerTipoCaminhao
        pickerTipoCaminhao.hidden = true
    }

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

    func numberOfComponentsInPickerView(pickerTipoCaminhao: UIPickerView) -> Int {
        return 1
    }

    func pickerView(pickerTipoCaminhao: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return arrayTipoCaminhao.count
    }

    func pickerView(pickerTipoCaminhao: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return arrayTipoCaminhao[row]
    }
    func pickerView(pickerTipoCaminhao: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        txtTipoCaminhao.text = arrayTipoCaminhao[row]
    }
}

它似乎将视图链接到项目名称,而在代码中它似乎引用了窗口控件。我做错了什么?

0 个答案:

没有答案