【问题标题】:UITableView Swift not scrolling SwiftUITableView Swift 不滚动 Swift
【发布时间】:2014-12-02 14:49:45
【问题描述】:

UITableView Swift 不滚动。伙计们,我有这个包含三个不同单元格的表格视图,并且表格视图在模拟器上渲染得很好,但是当我滚动它时它会立即跳回顶部。

导入 UIKit

class WalkthroughScreen2ViewController: UIViewController , UITableViewDataSource,UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()


        tableView.estimatedRowHeight = 300
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.scrollEnabled = true

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // Return the number of rows in the section.
        return 4
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->
        UITableViewCell {

            println(indexPath.row)
            if(indexPath.row == 0){

                var cell: wkscreen2Cell1TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell1") as wkscreen2Cell1TableViewCell

                return cell
            }
            if(indexPath.row == 1){

                var cell: wkscreen2Cell2TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell2") as wkscreen2Cell2TableViewCell

                return cell
            }
            if(indexPath.row == 2){
                println("cell3")
                var cell: wkscreen2Cell3TableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell3") as wkscreen2Cell3TableViewCell

                return cell
            }
            return UITableViewCell()

    }




}

【问题讨论】:

  • Swift 与这个问题无关,只是它是您编写的编程语言。标记这个问题“Swift”很好,但“UITableView Swift 不滚动 Swift”和“UITableView Swift 不滚动。 "对任何人都没有帮助。
  • 将 tableView.estimatedRowHeight 更改为 tableView.estimatedRowHeight = UITableViewAutomaticDimension
  • 当我更改行时,高度为 300,超过 300 像素的任何内容都不会显示
  • 您的单元格是否正确使用了自动布局?
  • 所以问题是你没有对tableview应用任何约束,所以它实际上仍然比你的设备高,不需要“滚动”。还注意到你的故事板场景中有大大的红色感叹号吗?是的,你需要解决这些问题。

标签: uitableview swift


【解决方案1】:

我遇到了你的问题,因为我有同样的问题。

要在模拟器中滚动,请按下并上下移动光标。如果还是不能滚动,那一定是bug。

【讨论】:

  • 哇@ujjiwal-nadhan 谢谢! Swift 和模拟器的新手,不知道这一点。很有帮助!
【解决方案2】:

您的 TableView 必须滚动,当您的单元格数量 > 10 时,例如(4 英寸屏幕)。要做的测试:为 TableView 添加十个单元格。而且它必须工作。

【讨论】:

    【解决方案3】:

    当您显然只显示 3 个单元格时,为什么要在 numberOfRowsInSection 中使用 return 4 ?您是否尝试将其设置为 3 ?

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题。将“tableView.dataSource = self”和“tableView.delegate = self”放在“viewDidLoad()”上后,问题就解决了。

      覆盖 func viewDidLoad() { super.viewDidLoad()

          tableView.dataSource = self
          tableView.delegate = self   
      }
      

      【讨论】:

        【解决方案5】:

        退出刺激器,清除 shift+command+k 然后运行 ​​(command+R) 应该可以工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-26
          相关资源
          最近更新 更多