繁体   English   中英

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

[英]swift table view controller is not scrollable

这是我的代码:

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

在我的情节提要中,我选择“ Basic作为单元格的样式。

我的问题是表格视图不可滚动,我只能看到前14个播放器,如下所示:

在此处输入图片说明

更新1

我将print("\\(indexPath.row)")放在override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {方法上,我看到只打印了15个值,其他值在哪里30吗

更新2

在表格视图上启用滚动 在此处输入图片说明

更新3

如您在此处看到的,启用了用户交互

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

这是你的答案。 检查鼠标。 在模拟器中,您应该单击以进行屏幕滚动。

暂无
暂无

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

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