【发布时间】:2019-01-10 18:58:45
【问题描述】:
您好,我已经为这个问题在网上搜索了很长时间,但我的 UITableViewController 中似乎存在一个错误,当我滚动时,导航栏标题会根据我滚动的位置而变化。
更新:我包含了我的表格视图控制器代码,因为我不确定它可能出错的地方。我不直接修改此代码中的导航标题,因为我可以直接在情节提要中进行。
似乎当我运行代码时,正确的标题会短暂出现,一旦数据加载,标题就会根据数据开始奇怪地变化。
class CustomCollectionsTableViewController: UITableViewController {
// Mark: Variables
var collections = [Collection]()
var currentCollectionID:String!
// Mark: IBOutlet
@IBOutlet var collectionsTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Mark: Delegate
collectionsTableView.delegate = self;
// Mark: Datasource
collectionsTableView.dataSource = self;
let url = "www.url.com"
ClientService.getCollections(url: url) { (receivedCollections) in
self.collections = receivedCollections
self.collectionsTableView?.reloadData()
}
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return self.collections.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "collectionTableViewCell", for: indexPath) as! CustomCollectionTableViewCell
title = self.collections[indexPath.row].name
cell.collectionTitle.text = title
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "displayProducts" {
if let indexPath = collectionsTableView.indexPathForSelectedRow{
var destinationVC = segue.destination as! CollectionViewController
let id = collections[indexPath.row].id
currentCollectionID = String(id)
destinationVC.collectionID = currentCollectionID
}
}
}
}
【问题讨论】:
-
您可能将您的标题设置为其他内容,可能是在 cellForRowAt 或 scrollViewDidScroll 之类的方法中。分享您的代码,以便我们更好地了解发生了什么
-
“Ergonomic”或“Synergistic”字样是否出现在数据或代码中?说到代码,那是什么样的?
-
@danh 我更新了帖子以包含我的表格视图控制器代码。 Ergonomic 和 Synergistic 这两个词确实出现了,但作为检索的数据。
-
@emrepun 我已经分享了代码,谢谢。
-
是的,正如我所怀疑的,你在 cellForRowAt 方法中设置了你的标题,检查下面的答案。
标签: swift uitableview uinavigationbar