верно (_____________)
tableView ошибка
то есть, я переделаю переход назад, и у меня должно отобразится?
разве моя переменная не бедет пустой, если вот так буду писать?*
var _categoryTitle: String = ""
она будет пустая только при создании VC, вы же с этого VC идете вперед, а это VC не уничтожается и когда вы делаете возврат на него, вы в эту переменную передаете строку.
в копошилке есть как раз видео про жизненный цикл ViewControllera, для лучшего понимания
вот в итоге что получилось, хочу по нажатию появлениа алерт, я ввожу цифру туда и по нажатию на окей перехожу назад вместе со строкой и этой цифрой, как вот это выполнить?
вот начало
func indexAlert(index:Int) {
let alert5 = UIAlertController(title: "Количество", message: nil, preferredStyle: .alert)
alert5.addTextField(configurationHandler: { textField in
textField.placeholder = "Введите количество"
})
let cancel = UIAlertAction(title: "Отмена", style: .cancel, handler: nil)
let buttonOk = UIAlertAction(title: "OK", style: .default, handler: { action in
if let kolMateriala = alert5.textFields?.first?.text {
print(kolMateriala)
}
self.navigationController?.popViewController(animated: true)
}
)
}
мне нужно было в двух местах передавать значения в предыдущий VC, в первом месте с помощб делегата передал, посмотрел как делается в копошике, ну там как бы все легко, (текст из тестового поля передать и все), спасибо зав советы, разбираюсь со вторым местом!!!
import UIKit
protocol MaterialTableDelegate {
func goToMaterial(info4: String)
}
class TableViewController: UITableViewController, ExpandableHeaderViewDelegate {
var delegateMaterial: MaterialTableDelegate?
var sections = [
Section(courseName: "Auto",
lessons: [ "Koleso",
"Mexanik"],
expanded: false),
Section(courseName: "Vochdenie",
lessons: ["parkovka",
"Boks",
"Zmeyka",
"Gorka"],
expanded: false) ]
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].lessons.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = sections[indexPath.section].lessons[indexPath.row]
return cell
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if sections[indexPath.section].expanded {
return 44
}
return 0
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 2
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = ExpandableHeaderView()
header.setup(withTitle: sections[section].courseName, section: section, delegate: self)
return header
}
func toogleSection(header: ExpandableHeaderView, section: Int) {
sections[section].expanded = !sections[section].expanded
tableView.beginUpdates()
for row in 0..<sections[section].lessons.count {
tableView.reloadRows(at: [IndexPath(row: row, section: section)], with: .automatic)
}
tableView.endUpdates()
}
func indexAlert(index:Int) {
let alert5 = UIAlertController(title: "Количество", message: nil, preferredStyle: .alert)
alert5.addTextField(configurationHandler: { textField in
textField.placeholder = "Введите количество"
})
let cancel = UIAlertAction(title: "Отмена", style: .cancel, handler: nil)
let buttonOk = UIAlertAction(title: "OK", style: .default, handler: { action in
if let kolMateriala = alert5.textFields?.first?.text {
print(kolMateriala)
let info4 = kolMateriala
self.delegateMaterial?.goToMaterial(info4: info4)
}
self.navigationController?.popViewController(animated: true)
}
)
}
я не до конца понимаю как по нажатию вынуть ту информацию на которую нажал, сделал делегат, хочется чтобы по нажатию на ячеку появился алерт, в него вести число, нажав окей, перейти на предыдущий vc вместе с данными и той цифрой которую ввел(строкой)