这是我的代码:
class PlayersNamesTableViewController: UITableViewController {
var players = [Player]()
let numberOfPlayers = 30
override func viewDidLoad() {
super.viewDidLoad()
loadPlayers()
}
func loadPlayers(){
for index in 0..<numberOfPlayers{
let player = Player(name: "Player \(index)")
players += [player]
}
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return players.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("playerCellIdentifier", forIndexPath: indexPath) as UITableViewCell
let player = players[indexPath.row]
cell.textLabel?.text = "\(player.name)"
return cell
}
}
在我的 Storyboard中,我选择 Basic
作为单元格的样式。
我的问题是表格 View 不可滚动,我只能看到前 14 个玩家,如下所示:
更新 1
我将 print("\(indexPath.row)")
放在 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
方法上我可以看到只打印了 15 个值,其他 30 个在哪里?
更新2
更新3
已启用用户交互,正如您在此处看到的
最佳答案
这是你的答案。检查你的鼠标。在模拟器中,您应该点击屏幕并滚动。
关于ios - 快速 TableView Controller 不可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32455372/