UITableView Swift未滚动Swift
UITableView未滚动。伙计们,这个表视图有三个不同的单元格,表视图在模拟器上呈现得很好,但当我滚动时,它立即跳回顶部 导入UIKitUITableView Swift未滚动Swift,uitableview,swift,Uitableview,Swift,UITableView未滚动。伙计们,这个表视图有三个不同的单元格,表视图在模拟器上呈现得很好,但当我滚动时,它立即跳回顶部 导入UIKit class WalkthroughScreen2ViewController: UIViewController , UITableViewDataSource,UITableViewDelegate { @IBOutlet weak var tableView: UITableView! override func viewDidLo
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()
}
}
例如,当单元格数>10(4英寸屏幕)时,TableView必须滚动。要做的测试:为TableView添加十个单元格。而且它必须工作。当单元格数>10时,例如(4英寸屏幕),您的TableView必须是滚动的。要做的测试:为TableView添加十个单元格。而且它必须工作。当您显然只显示3个单元格时,为什么在
numberOfRowsInSection
中返回4?您是否尝试将其设置为3?当您显然只显示3个单元格时,为什么在numberOfRowsInSection
中返回4?你试过把它设为3吗?我回答了你的问题,因为我有同样的问题
要在模拟器中滚动,请按住并上下移动光标。如果你仍然无法滚动,那一定是个bug。我回答了你的问题,因为我有同样的问题
要在模拟器中滚动,请按住并上下移动光标。如果您仍然无法滚动,那一定是一个bug。我也有同样的问题。将“tableView.dataSource=self”和“tableView.delegate=self”放在“viewDidLoad()”上后,问题就解决了 重写func viewDidLoad(){ super.viewDidLoad()
我也遇到了同样的问题。在将“tableView.dataSource=self”和“tableView.delegate=self”放在“viewdiload()”上之后,问题就解决了 重写func viewDidLoad(){ super.viewDidLoad()
退出刺激器,clean shift+command+k然后运行(command+R)应该有效。退出刺激器,clean shift+command+k然后运行(command+R)应该有效。Swift与这个问题无关,只与您编写它的编程语言有关。将这个问题标记为“Swift”很好,但是“UITableView Swift不滚动Swift”和“UITableView Swift不滚动”。"对任何人都没有帮助。当您将tableView.estimatedRowHeight更改为tableView.estimatedRowHeight=UITableViewAutomaticDimensions时会发生什么情况当我更改行的高度为300,并且任何超过300px的内容都不会显示您的单元格是否正确使用autolayout?因此,问题在于您没有对tablevie应用任何约束w、 因此,它实际上仍然比你的设备高,不需要“滚动”。请注意,在你的故事板场景中有红色的感叹号?是的,你需要修复这些。斯威夫特与这个问题无关,只与你编写它的编程语言有关。将这个问题标记为“斯威夫特”很好,但是“UITableView Swift不滚动Swift”和“UITableView Swift不滚动”。"对任何人都没有帮助。当您将tableView.estimatedRowHeight更改为tableView.estimatedRowHeight=UITableViewAutomaticDimensions时会发生什么情况当我更改行的高度为300,并且任何超过300px的内容都不会显示您的单元格是否正确使用autolayout?因此,问题在于您没有对tablevie应用任何约束w、 所以它实际上仍然比你的设备高,不需要“滚动”。请注意,你的故事板场景中有大红色感叹号?是的,你需要修复这些。哇@ujjiwal nadhan谢谢!Swift和模拟器新手,但不知道。非常有用!哇@ujjiwal nadhan谢谢!Swift和模拟器新手,但不知道。非常有用!
tableView.dataSource = self
tableView.delegate = self
}