I have a working picker view with following lines of code
@IBOutlet var myPicker: UIPickerView! var colors: [String] = ["red","green","blue"] override func viewDidLoad() { super.viewDidLoad() myPicker = UIPickerView() myPicker.dataSource = self myPicker.delegate = self } func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { return 1 } func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return colors.count } func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! { return colors[row] as! String } i have a button when i click i want to remove all the old values (i'e red, green and blue) and update with the new values (yellow, black)
func buttonClicked(sender: UIButton!) { var btn:UIButton = sender; colors = ["yellow", "black”] myPicker.reloadAllComponents() } but unfortunately the above code is not working, i'm a newbie in swift and dont know how to implement this, can someone please help me on this?
buttonClickedis called when your button is clicked.