gpt4 book ai didi

swift - 如何在不使用 UITextField 的情况下将 UIToolbar 添加到 UIPickerView?

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:17 31 4
gpt4 key购买 nike

我在没有 UITextField 的情况下使用了 UIPickerView。用户点击按钮后,将显示 UIPickerView

无论如何,我不知道如何关闭 UIPickerView。我试图用 UIToolbar 设置 inputAccessoryView 但编译器说它是 get-only 属性。

我的代码:

    let toolbar = UIToolbar()
toolbar.barStyle = UIBarStyle.default
toolbar.isTranslucent = true
toolbar.sizeToFit()

let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(RegisterViewController.pickerDoneButton))
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: self, action: nil)
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(RegisterViewController.pickerCancelButton))

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

pickerView.inputAccessoryView = toolbar

Error: Cannot assign to property: 'inputAccessoryView' is a get-only property

enter image description here

最佳答案

尝试将 subview 添加到 UIPickerView

关于swift - 如何在不使用 UITextField 的情况下将 UIToolbar 添加到 UIPickerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42038256/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com