【发布时间】:2017-09-28 09:56:47
【问题描述】:
我的导航标题和使用代码设置有问题。
这是我的代码结构:
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 = "title name"设置为viewDidLoad
标签: ios swift uinavigationcontroller ios-simulator swift4