我創建了一個靜態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
好吧,但你的單元格的自定義字段是如何定義的? –