maybe someone can help me. I made a copy of the project “add rows to TableView” from IOSCcreator. Now I change the file where an item can be added with a pickerview. At line 44 (pickOption = carName.text) it fails:
Cannot assign a value of type String to a value of type [String].
Try a lot of things but nothing works.
import UIKit
class CarDetailViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var carName: UITextField!
var pickOption = ["Opel", "Mercedes", "Hyundai", "Kia"]
override func viewDidLoad() {
super.viewDidLoad()
var pickerView = UIPickerView()
pickerView.delegate = self
carName.inputView = pickerView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickOption.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickOption[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
carName.text = pickOption[row]
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "doneSegue" {
pickOption = carName.text
}
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.view.endEditing(true)
}
}