Ich habe ein Problem mit meinem Navigationstitel und setze ihn mit Code. HierIch kann das UINavigationBarTitleItem nicht festlegen. Wie stelle ich es ein?
ist die Struktur meines Code:
Navigation Controller -> TableView -> UIScreen where i want to set the title.
Hier ist mein Code:
Tableviewcontroller:
import UIKit
class ProductsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UserCell.self, forCellReuseIdentifier: cellId)
}
let cellId = "cellId"
let products = [
"Happy Face",
"Sad Face",
"High Five",
"Angry Face",
"The Earth"
]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return products.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
let product = products[indexPath.row]
cell.textLabel?.text = product
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let buyProductViewController = BuyProductViewController()
let product = products[indexPath.row]
buyProductViewController.nameOfItem = product
buyProductViewController.navigationItem.title = product
performSegue(withIdentifier: "segue", sender: self)
}
}
class UserCell: UITableViewCell {
}
Einstellung meinen Titel-View-Controller:
import UIKit
Klasse BuyProductViewController: UIViewController {
var nameOfItem: String? {
didSet {
print(nameOfItem)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Ich würde es sehr schätzen, wenn any1 mir helfen könnte, weil ich sehr aufgeregt bin und auf diese über eine Woche gearbeitet und nur kam gerade über Stapelüberlauf.
Danke.
Versuch 'self.title = "Titelname"' set in 'viewDidLoad' –