【发布时间】:2016-11-19 14:39:09
【问题描述】:
我一直在寻找答案,但找不到任何明确的解决方案。我正在制作一个具有相同 UIpickerViews 的三个 UItextFields 的视图控制器。如果特定行已经在另一个 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]
} 非常感谢您的帮助!
【问题讨论】:
标签: swift uipickerview