У меня есть контроллер основного вида с UITableView.В табличном представлении есть 2 ячейки, прототипированные в IB.
Прототипированные ячейки
Первая ячейка находится в секции 0, а вторая ячейка - в секции 1 (всегда нанижняя часть таблицы).
Вот мое определение таблицы в главном ViewController:
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return itemNames.count
} else {
return 1
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Created additional section where will be the cell for adding items (always at bottom)
switch indexPath.section {
case 0:
let cellIdentifier = "itemCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ItemTableViewCell
cell.itemNameTextView.text = itemNames[indexPath.row]
let currentImage = itemImages[indexPath.row]
cell.itemStateButton.setImage(UIImage(named: currentImage), for: UIControlState.normal)
return cell
case 1:
let cellIdentifier = "addItemCell"
let addCell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! ItemTableViewCell
addCell.addItemButton.setImage(UIImage(named: "plus-math-40"), for: UIControlState.normal)
return addCell
default:
return UITableViewCell()
}
}
Все выходы для ячеек определены в пользовательском UITableViewCell:
class ItemTableViewCell: UITableViewCell {
@IBOutlet var itemNameTextView: UITextView!
@IBOutlet var itemStateButton: UIButton!
@IBOutlet var addItemButton: UIButton!
@IBOutlet var addTextView: UITextView!
Как я могу получить доступ к значениям (чтение и изменение) переменных выходов в ItemTableViewCell из основного ViewController?
Например, когда во второй ячейке нажата кнопка «+», мне нужно, чтобы TextView стал FirstResponder, изатем сохраните значение TextFiled.
А также мне нужно отредактировать TextFields в ячейках сечения 0 и затем сохранить данные из них.