ナビゲーションタイトルに問題があり、コードで設定しています。ここでUINavigationBarTitleItemを設定できません。どうすれば設定できますか?
は、私のコードの構造である:ここで
Navigation Controller -> TableView -> UIScreen where i want to set the title.
は私のコードです:
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 {
}
:
import UIKit
クラスBuyProductViewController:のUIViewController {
var nameOfItem: String? {
didSet {
print(nameOfItem)
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
、私は非常に動揺していますし、一週間かけてこれに取り組んとばかりスタックオーバーフローに出くわしてきたので、any1は私を助けることができれば、私は非常に感謝します。
ありがとうございました。
試し 'self.title = "タイトル名を"' 'viewDidLoad' –