简体   繁体   English

快速表格视图控制器不可滚动

[英]swift table view controller is not scrollable

this is my code: 这是我的代码:

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
    }
}

in my storyboard, i select Basic for the style of the cell. 在我的情节提要中,我选择“ Basic作为单元格的样式。

My problem is that the table view is not scrollable, i just can see the first 14 players, like this: 我的问题是表格视图不可滚动,我只能看到前14个播放器,如下所示:

在此处输入图片说明

Update 1 更新1

I put print("\\(indexPath.row)") on the override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { method and I can see that there are just 15 values being printed, where are the other 30? 我将print("\\(indexPath.row)")放在override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {方法上,我看到只打印了15个值,其他值在哪里30吗

Update2 更新2

Scroll is enabled on the table view 在表格视图上启用滚动 在此处输入图片说明

Update3 更新3

User Interaction is enabled, as u see here 如您在此处看到的,启用了用户交互

在此处输入图片说明 在此处输入图片说明

Here is your answer. 这是你的答案。 Check your mouse. 检查鼠标。 In simulator you should click to screen and scroll. 在模拟器中,您应该单击以进行屏幕滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM