- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Swift 3 iOS 10:我想在 UIAlertView
中添加 UIPickerView
以便我可以选择项目并将其值设置为 textField。我可以用 UIView
做到这一点,但我想以更好、更自然的方式改进它。是否可以这样做或有什么出路?
提前致谢!
这是我做的,
最佳答案
虽然 Apple 建议我们不要这样做,但您确实可以将选择器 View 添加到您的警报 View Controller 。 UIAlertViewController
除了一个普通的 View Controller 之外没有任何神奇之处。您需要做的就是显示带有大量新行的标题文本(即“选择\n\n\n\n\n\n\n\n\n\n\n\n”)以增加alert高度,然后调用alertViewController.addSubview(datePicker)
然而,问题是为什么您需要编写额外的代码来操作警报 View Controller 并处理要设置值的文本字段?这是另一种更易于维护和实现的方法。
首先创建您的选择器 View 并对其进行配置。
let picker = UIPickerView()
picker.delegate = self
picker.dateSource = self
// configure
然后对于您的每个文本字段,只需调用它
tf1.tag = 1
tf2.tag = 2
tf3.tag = 3
tf1.delegate = self
tf2.delegate = self
tf3.delegate = self
tf1.inputView = picker
tf2.inputView = picker
tf3.inputView = picker
不在您的文本字段委托(delegate)方法中,存储用户单击的文本字段并重新加载选择器 View 数据
var tfTag = 0
func textFieldDidBeginEditing(_ textField: UITextField) {
tfTag = textField.tag
picker.reloadAllComponents()
}
最后,在所有选择器 View 数据源或委托(delegate)方法中,根据每个文本字段的唯一标签号加载不同的数据集
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if tfTag == 0 {
if component == 0 {
return "1"
}else if component == 1 {
return "2"
}else if component == 2 {
return "3"
}else{
return "4"
}
}else if tfTag == 1 {
//...
}else{
//...
}
}
关于swift - 如何在 uialertview swift 3 中添加 uipickerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44959663/
我正在编写一个汽车租赁应用程序,用户必须指定取车和还车位置。 第一步,用户必须选择取货/返回办公室的区域/区域。选择区域后,他必须从该区域可用的办事处列表中进行选择。 为了选择办公室,我使用了 4 个
我正在尝试创建一个文本框,当选择该文本框时,UIPickerView 将打开并提供可供选择的选项。选择后,UIPickerView 将隐藏,所选项目将显示在文本框中。当我运行此程序时,数组中的第一个元
我有多个 UIPickerView 的问题,我在 UICollectionView 上有 8 个,当我滚动第一个 PickerView 和第五个 PickerView 时,它开始自行滚动并采用与第一个
我正在阅读一本 Swift OOP 书籍,我理解实例方法具有将在函数中使用的参数的想法。不清楚的是,在遵循 UIPickerViews 和 UITableViews 的在线教程时,有些方法将 UIPi
我有两个不同的 UIPickerView用户选择第一个 UIPickerView来自 didSelectRow第一个选择器,我得到第二个的输入 UIPickerView .我尝试为单个选择器设置标签,
函数 pickerView() 在 ViewLoad 上调用的代码 private func createPickerView(){ picker = UIPickerView(frame:
我创建了 UIPickerView 如下。现在我想让它 resignFirstResponder 如果用户在其他地方点击然后 UIPickerView 我怎么能实现呢。我已经按照以下方式创建了 UIP
我的 View Controller 中有两个 UIPickerview,pickerView1 和 pickerView2。 我在这里想要实现的是,当我从 pickerView1 中选择一个字符串时
我们正在使用 UIPickerView允许用户从选项列表中进行选择。我们正在添加 UIPickerView作为容器 UIView 的 subview 。然后我们将一个 UITapGestureReco
好吧,我不知道如何处理这个问题。 我有一个 UITextField,我根据 XML 文件的定义将其动态添加到 UITableView,在 XML 文件中,我可以将列表指定为其中一种数据类型,然后我所做
我现在有2个UIPickerView,以后想再添加3个,代码如下: -(void)viewDidLoad{ Pos_x = 5; Pos_y = 70; for (i= 0; i<2; i++) {
UIPickerView 的 selectRow:inComponent:animated:调用pickerView:didSelectRow:inComponent: ? 否则,我可以自己打电话吗?
我有两个按钮,打开一个 UIPickerView @IBOutlet weak var convertFromButton: UIButton! @IBOutlet weak var convertT
祝大家有美好的一天 我尝试在主题行中解释我的查询。据我了解,从代码中看到,所有 pickerview 都在 ViewDidLoad() 中初始化,这意味着它们都有自己的数据集。作为数据验证的一部分(在
我试图在 PickerView 中显示血型,但由于某些原因,选项仅显示为问号! 这是我的代码: class RegisterViewController: UIViewController,
我正在尝试将工具栏添加到 UIPicker . 我已经看到正确的方法是这样: UIToolbar* toolbarWeight= [[UIToolbar alloc] initWithFrame:CG
我将如何向 uipickerview 添加手势事件来更改选项卡?我必须创建一个自定义类,但是,我不知道如何处理 uipickerview。我当前在 uiviews 中存在手势来执行此操作,但我在使用
我想做的是: 显示了一个 UIPickerView。如果用户触摸选定的行,则该行将被锁定(它是多组件选择器),并且其他组件可以自由旋转。如果该行已被锁定并且用户触摸了锁定的行,则该行将被解锁并可以自由
我有两种看法。第一个:第一个 View Controller 第二:SecondViewController FirstView Controller 是我的 UINavigationControll
使用 UISegmentedControl,您可以在不选择任何内容的情况下启动它。如何使用 UIPickerView 做到这一点?看起来显示默认为索引 0。 谢谢 最佳答案 选择器轮必须停留在某些值上
我是一名优秀的程序员,十分优秀!