我创建了一个静态tableView,并希望将来自每个tableViewCell(所有单元格都是不同的自定义tableViewCells)的数据保存到CoreData。如何迭代所有按钮按下的TableViewCells?我没有使用Storyboard,所以我没有IBOutlets。Swift:如何遍历按钮上的所有tableViewRows按
编辑:对不起,也许我应该指定我的问题。请参阅下面的代码。 我有3个CustomCells。 FirstCustomCell包含一个Textfield,SecondCustomCell一个UIPickerView和一个ThirdCustomCell一个UIDatePicker。控制器还包含一个saveButton()。如果我按下按钮,我想从TextField,UIPickerView和UIDatePicker获得输入。
//TableViewController
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
return tableView.dequeueReusableCell(withIdentifier: cellId1) as! FirstCustomCell //includes a UITextField
case 1:
return tableView.dequeueReusableCell(withIdentifier: cellId2) as! SecondCustomCell //includes a UIPickerView
case 2:
return tableView.dequeueReusableCell(withIdentifier: cellId3) as! ThirdCustomCell //includes a UIDatePicker
default:
return UITableViewCell(style: .default, reuseIdentifier: nil)
}
}
如何我在TableViewController从文本字段,UIPickerView和的UIDatePicker访问saveButton()输入?
这些单元格模板是如何定义的?用XIB文件? –
作为一个类继承UITableViewCell – eberhapa
好吧,但你的单元格的自定义字段是如何定义的? –