J'ai un problème avec mon titre de navigation et je le configure avec du code.Je ne peux pas définir UINavigationBarTitleItem. Comment puis-je le définir?
Voici la structure de mon code:
Navigation Controller -> TableView -> UIScreen where i want to set the title.
Voici mon 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 {
}
Réglage mon titre View Controller:
import UIKit
classe BuyProductViewController: UIViewController {
var nameOfItem: String? {
didSet {
print(nameOfItem)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
Je serais très reconnaissant si any1 pourrait me aider parce que je suis très en colère et je travaille sur ce plus d'une semaine et juste tombé sur un débordement de pile.
Merci.
essayer 'self.title = "nom du titre"' 'mis en viewDidLoad' –