- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在寻找答案,但找不到任何明确的解决方案。我正在制作一个具有三个具有相同 UIpickerViews 的 UItextFields 的 View Controller 。如果已在另一个 UItextField 中选择了特定行,如何使不可选择的特定行改变颜色或消失?
这是我的代码:
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return Array.count
}
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
if "Shake" {
let attributesUnavailable = [NSForegroundColorAttributeName: UIColor.gray]
let attributedTitle = NSAttributedString(string: "Shake", attributes: attributesUnavailable)
return attributedTitle
}
let attributesAvailable = [NSForegroundColorAttributeName: UIColor.black]
let attributedTitle = NSAttributedString(string: Array[row], attributes: attributesAvailable)
return attributedTitle
}
public func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func donePicker() {
actionTextField1.resignFirstResponder()
actionTextField2.resignFirstResponder()
actionTextField3.resignFirstResponder()
}
@IBAction func save3(_ sender: AnyObject) {
if (behaviorTextField1.text?.isEmpty)! {
let behavior1Empty = UIAlertController (title: "Error", message: "Please fill-In Behavior Names and set corresponding Actions", preferredStyle: UIAlertControllerStyle.alert)
self.present(behavior1Empty, animated:true, completion:nil)
behavior1Empty.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
}))
}
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if Array[row] {
pickerView.selectRow(row + 1, inComponent: 0, animated: true)
}
}
if pickerView.tag == 1 {
actionTextField1.text = Array[row]
}
else if pickerView.tag == 2 {
actionTextField2.text = Array[row]
}
else {
actionTextField3.text = Array[row]
}我们将非常感谢您的帮助!
最佳答案
它不像UITableView
那么简单,但是有一个很好的方法,似乎与在Settings.app中设置IOS日期时使用的方法相同。
示例:
func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
if row_cant_be_selected {
let attributesUnavailable = [NSForegroundColorAttributeName: UIColor.grayColor()]
let attributedTitle = NSAttributedString(string: YOUR_TITLE_FOR_ROW, attributes: attributesUnavailable)
return attributedTitle
}
let attributesAvailable = [NSForegroundColorAttributeName: UIColor.blackColor()]
let attributedTitle = NSAttributedString(string: YOUR_TITLE_FOR_ROW, attributes: attributesUnavailable)
return attributedTitle
}
selectRow(_:inComponent:animated:)
即可“强制”选择另一行。示例:
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if ROW_CANT_BE_SELECTED {
pickerView.selectRow(row + 1, inComponent: 0, animated: true)
}
}
IE:如果第 1 行不可用,则在 pickerView(_:didSelectRow:inComponent:
) 上只需调用 pickerView.selectRow(row + 1, inComponent: 0,animated: true)
code>。这将使 UIPickerView
跳到下一个元素。只需注意最后一个元素。
请注意row + 1
,如果当前row
是最后一行,则应该改为row - 1
。
其他方法是删除数据源上那些不可用的元素。只需重新加载其他选择器 View 数据即可。
关于swift - 在具有相同 pickerview 的 UItextField 中选择行后,使行(在 pickerview 中)不可选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40694104/
我在一个 View Controller 上使用多个pickerview。我在相应的选取器 View 中获得正确的数据,但选取器 View 中的行对称 View 不正确。第一个选择器 View 中的数
我在 View 中有多个文本字段,其中输入 View 设置为 pickerView,但是根据文本字段,应该显示不同数量的选择行。当您单击选取器 View 外部,然后单击下一个文本字段时,此方法工作正常
我有两个 pickerView,即 pickerView1 = car_make、pickerView2 = car_model。 如果我选择 car_make = Kia,我希望 pickerVie
我创建了一个使用数组作为数据源的 UIPickerView,我想在第三个组件上选择一个项目后隐藏第四个组件上的一些项目。我该怎么做? class ViewControllerEspessuras: U
我尝试使用此方法selectedRow(inComponent: 0),但它对我不起作用。当选择器不活动时,有什么方法可以从选择器中获取第一个/默认值吗? func pickerView(_ pick
我一直在寻找答案,但找不到任何明确的解决方案。我正在制作一个具有三个具有相同 UIpickerViews 的 UItextFields 的 View Controller 。如果已在另一个 UItex
UIPickerView 显示数据,但不会传输到 UITextField。 我检查了其他帖子来比较我的代码,仍然找不到解决方案。非常感谢您的帮助。 import UIKit class ViewCon
当我尝试对 pickerView 中的特定行执行操作时,我遇到了一个问题。 例如,我在 pickerView 中有多个项目,而在核心数据中我有计数器属性,所以我需要做的是,一旦我从 pickerVie
我在现有应用程序中有一个使用小数位的自定义键盘。我正在尝试实现英制测量。 所以我从键盘上删除了小数点,并添加了一个选择器 View ,我希望在其中包含 1/32 -> 31/32 之间的所有可能的分数
当我点击文本字段时,会出现输入区域,但只有 1 行,内容为空白。 (我期望 3 行:a、b 和 c) 我将 numberOfRowsInComponent 和 titleForRow 函数中的返回值更
我正在尝试制作一个 pickerView,用户可以在其中选择他/她的体重...在 Swift 2.2 中,我正在考虑制作这样的 Range: var weightList: [Int] = Array
我是 iOS 新手。谁能帮助我如何使用 PickerView 来显示年份和月份?如何设置每列的大小? - (NSInteger)numberOfComponentsInPickerView:(UIPi
我使用 inputView 在单击文本字段时显示 pickerView。然后我想用数字 1-100 填充 pickerview。我有一些我认为可以工作的代码,但是当我运行程序并单击文本字段时,它只会弹
我制作了一个字体选择器,可以显示轮子内的所有字体。 我现在需要添加 2 个额外的部分来更改字体大小和样式(粗体、斜体、下划线)。 样式和大小是 UIFont 类的成员吗?如果是这样,如何访问它们? 这
这是我的代码: @synthesize pickerLetter, pickerNumber, pickerSymbol; - (void)viewDidLoad { [super viewDidL
我想要做的是根据从选择器中选择的内容显示特定的文本字符串。例如,可以在选择器中选择蓝色、绿色和黄色选项。当您选择蓝色时,一些文本(例如,我喜欢海洋!)会输出到标签。 我已经一切正常,除了在选择器中选择
我试图调出一个选择器 View 而不是键盘来放入文本字段,但我的选择器 View 没有显示。 #import "SettingsViewController.h" #import "FindCla
我正在从一个 JSON 文件中解析一些数据 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"airports" ofType
我正在尝试获取其中包含数字列表的选择器 View 。 到目前为止,我可以获得包含所有数字的字符串,但是当将其放入选择器 View 时,选择器 View 始终为空。你能看看我的代码,让我知道哪里出错了吗
我使用了一个带有四个组件的 UIPickerView 来在没有键盘的情况下输入数字。我添加了一个小数点,只有一个“。”在 UILabelView 中。查看屏幕了解想法。 我的 UIPickerView
我是一名优秀的程序员,十分优秀!