Erstellen Sie eine Variable für indexPaths
, die eine UIPickerView
haben müssen, um zu überprüfen:
var indexesNeedPicker: [NSIndexPath]?
Dann hängen Sie jene indexPaths
im didSelectRowAtIndexPath
Verfahren. entfernen Sie sie auch, wenn sie bereits hinzugefügt wurden
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexesNeedPicker != nil {
if indexesNeedPicker!.contains(indexPath) == true {
indexesNeedPicker!.removeAtIndex((indexesNeedPicker!.indexOf(indexPath))!)
return
}
}
indexesNeedPicker?.append(indexPath)
self.table.deselectRowAtIndexPath(indexPath, animated: true)
self.table.reloadData()
}
Dann wird Ihr cellForRowAtIndexPath
Methode
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Default, reuseIdentifier: "cell")
if indexesNeedPicker?.contains(indexPath) == true {
let pickerView = UIPickerView(frame: cell.frame)
pickerView.delegate = self
pickerView.dataSource = self
cell.addSubview(pickerView)
}
return cell
}
die Delegierten zu Ihrem Viewcontroller
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource {
Und schließlich hinzufügen und anpassen, um die Methoden hinzufügen bearbeiten :
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
<#code#>
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
<#code#>
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
<#code#>
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
<#code#>
}