gpt4 book ai didi

ios - TableView 仅在单击时显示内容

转载 作者:可可西里 更新时间:2023-11-01 00:59:21 24 4
gpt4 key购买 nike

我正在制作一个 TableView 来显示我们镇上的商店及其类别。我在表格 View 中显示商店时遇到问题:首先,第一家商店不显示,其次,商店只有在点击时才可见。您可以找到问题的视频 here

表格 View 的代码:

import UIKit

class MasterTableViewController: UITableViewController {

// MARK: - Properties
var detailViewController: DetailViewController? = nil
var winkels = [Winkel]()

// MARK: - View Setup
override func viewDidLoad() {
super.viewDidLoad()

winkels = [
Winkel(category:"Literature", name:"Standaard"),
Winkel(category:"Literature", name:"Acco"),
Winkel(category:"Clothing", name:"H&M"),
Winkel(category:"Clothing", name:"C&A"),
Winkel(category:"Clothing", name:"Patio"),
Winkel(category:"Restaurants", name:"De 46"),
Winkel(category:"Restaurants", name:"Het hoekske"),
Winkel(category:"Supermarkets", name:"Carrefour"),
Winkel(category:"Supermarkets", name:"Colruyt")
]

if let splitViewController = splitViewController {
let controllers = splitViewController.viewControllers
detailViewController = (controllers[controllers.count - 1] as! UINavigationController).topViewController as? DetailViewController
}
}

override func viewWillAppear(animated: Bool) {
clearsSelectionOnViewWillAppear = splitViewController!.collapsed
super.viewWillAppear(animated)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

// MARK: - Table View
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return winkels.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)


let winkel = winkels[indexPath.row]
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
cell.textLabel!.text = winkel.name
cell.detailTextLabel?.text = winkel.category
return cell
}

// MARK: - Segues
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showDetail" {
if let indexPath = tableView.indexPathForSelectedRow {
let winkel = winkels[indexPath.row]
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
controller.detailWinkel = winkel
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}

}

有没有人知道如何解决这些问题?提前致谢!

最佳答案

删除行
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell") 因为你已经有了
var cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

关于ios - TableView 仅在单击时显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37633729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com