swift3中使用pickerviiew时不会触发textFieldDidEndEditing

迪帕克·亚迪达(Deepak Yadeedya)

textFieldDidEndEditing在Swift 3中使用选择器视图时,不会触发文本字段委托方法没有按钮可以动态调用委托。

您可以在下面看到我的代码。

图片在这里

import UIKit

class ThroewViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,UITextFieldDelegate {



    @IBOutlet weak var pickerText: UITextField!


    let thePicker = UIPickerView()
    var dashTitle_Arr = ["One","Two","Three","Four","Five","Six"]

    override func viewDidLoad() {
        super.viewDidLoad()

        pickerText.delegate = self
       thePicker.dataSource = self
        thePicker.delegate = self
       pickerText.inputView = thePicker



    }


    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

        return dashTitle_Arr .count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {


        return dashTitle_Arr [row]     }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {


        pickerText.text = dashTitle_Arr [row]

    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        addIntoArray(text: textField.text)
    }

    func addIntoArray(text: String?) {

        guard let text = text, text.characters.count > 0 else {

            return
        }

        dashTitle_Arr.append(text)
        thePicker.reloadAllComponents()
    }
}
Sanjukta

还有的属性picker-view就是accessoriesView创建tool bar带有done或的cancel按钮并将其设置在选择器视图的中assessoriesView

在工具栏中,button action写出textfield.resignFirstResponder()AftertextFieldDidEndEditing方法,激发委托方法

这对我来说可以。希望对您有帮助。谢谢

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Swift3中使用SwiftyJSON

在swift3中使用fetchedResultsController

编码日期格式以在 swift3 中的 json 中使用它时出错

在swift3中使用字节

如何在swift3中使用数据初始化结构变量

在 Swift 4 中使用 MVVM 绑定不会在 ViewController 中触发事件

如何在 swift3 XMLParse 中使用 urlsession

使用firebase swift3时出现异常

Swift3中的NSCalendar

使用线程时不会触发Pyttsx3回调

在 swift3 中不使用 Uiimageview 更改 UIImage 颜色

使用swift3在tableview中搜索栏和节

使用firebase的swift3中的时间戳问题

Swift3中的UUID,但使用“版本1”样式的UUID

使用 Chrome 时不会触发选择选项中的功能

使用大标题时,不会触发UIScrollView中的UIRefreshControl

如何使用Swift3从Firestore集合中使用检索到的数据填充TableView

Swift3 iOS-如何使UITapGestureRecognizer触发功能

Swift3多按钮动态编码触发事件

swift3中UnsafeMutablePointer中的错误

在 Swift3 iOS 中使用字符串参数对对象数组进行排序

Swift3:如何在NSArray中使用用户默认数据?

如何在swift3项目中使用目标c视图控制器

在IBM Cloud Kubernetes Service中使用IBM App ID时,不会触发认证过程

当我在DataGridTemplateColumn.CellTemplate中使用TextBox时,不会触发DataGrid.BeginningEdit事件

在这些方法中使用setState时,为什么componentWillUpdate()和componentWillMount()不会触发渲染函数?

如何在iOS,Swift3,Alamofire 4中使用多部分表单数据将图像作为参数上传以及其他参数

在Objective-C中使用时,有时不会调用Swift类中声明的运算符重载“ <”

Swift3中的可选结构