2014-12-02 90 views
1

UITableView Swift不滚动。伙计们我有三个不同的单元格和表视图在模拟器上呈现的表格视图很好,但是当我滚动它立即跳回到顶部。UITableView Swift不滚动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() 

    } 




} 
+1

Swift与这个问题无关,除了它是你编写它的编程语言。标记这个问题“Swift”很好,但“UITableView Swift不滚动Swift”和“UITableView Swift不滚动”。对任何人都没有帮助。 – mattyohe 2014-12-02 14:55:02

+0

将tableView.estimatedRowHeight更改为tableView.estimatedRowHeight = UITableViewAutomaticDimension – mattyohe 2014-12-02 14:56:17

+0

时发生了什么当我更改行的高度为300,并且不显示超过300px的任何内容时 – 2014-12-02 15:41:36

回答

0

你的TableView必须滚动,当你的细胞> 10的计数,例如(4寸屏)。测试:为TableView添加十个单元格。它必须奏效。

0

为什么你return 4numberOfRowsInSection当你显然只显示3个细胞?你有没有试过把它设置为3?

6

我登陆你的问题,因为我有同一个。

要在模拟器中滚动,请按下并上下移动光标。如果你仍然无法滚动,它一定是一个错误。

+0

WOW @ ujjiwal-nadhan谢谢!新来Swift和模拟器,并不知道这一点。很有帮助! – Lucy 2017-10-21 16:46:33