【发布时间】: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