2017-11-30 11 views
1

私は3つのUITextViewを持つフォームを持っています。私はテキストフィールドのタップにUIPickerViewを表示したい。私はそれのためのコードの下に書かれている -UIPickerView - UITextView TouchUpで動作しません

@IBAction func selectServiceBook(_ sender: UITextField) { 

    let message = "\n\n\n\n\n\n" 
    let alert = UIAlertController(title: "Select Service Book", message: message, preferredStyle: UIAlertControllerStyle.alert) 
    alert.isModalInPopover = true 

    let pickerFrame = UIPickerView(frame: CGRect(x: 20, y: 20, width: 200, height: 140)) // CGRectMake(left, top, width, height) - left and top are like margins 
    pickerFrame.tag = 666 
    //set the pickers datasource and delegate 
    pickerFrame.delegate = self 

    //Add the picker to the alert controller 
    alert.view.addSubview(pickerFrame) 
    let okAction = UIAlertAction(title: "OK", style: .default, handler: { 
     (alert: UIAlertAction!) -> Void in 
     self.ServiceBook.text = self.selectedServiceBook 
    }) 
    alert.addAction(okAction) 
    self.present(alert, animated: true, completion: { 
     self.ServiceBook.text = self.selectedServiceBook 
    }) 
} 

これは、2つのフィールドの仕事をしていませんが、ServiceBookそれキーボードのタップに代わりピッカービューのオープン取得します。画面の他の場所をタップすると、ピッカービューがポップアップします。だから私の前提はEditingDidEndイベントを参照しているEditingDidBeginの代わりです。

どうすれば確認できますか?ここで

答えて

1

は例

let myPickerProject = [ "Project 1", "Project 2", "Project 3", "Project 4", "Project 5", "Project 6"] // to feed row 
pickerProject.delegate = self 
let pickerProject = UIPickerView() 
let txtFiled = UITextField.init(frame: <#T##CGRect#>) 
txtFiled.inputView = pickerProject 
func numberOfComponents(in pickerView: UIPickerView) -> Int { 
    return 1 
} 
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
    return myPickerProject.count 
} 

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
    return myPickerProject[row] 
} 

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
    let selectedvalue = myPickerProject[row] 
} 
ある
関連する問題