如何保持表观滚动以及如何在swift3中的原型电视和tableview之间删除空空间



我有两个关于swift3

中的tableview的问题

在这里,我的tableview不滚动,即使我取消选中" uiview属性检查器"中的调整滚动视图插图,然后在单元格上方也没有删除空间。

在这里为什么我的tableview甚至启用了滚动如何滚动tableView在我的代码中有任何事情要做

请在两个问题中帮助我

我已经写了如下

的代码
import UIKit
class movieViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    @IBOutlet weak var tableviewLayout: UITableView!
    var itemsArray = ["One","Two","Three","Four","Five","six","Seven","Eight","Nine","Ten"]
    override func viewDidLoad() {
        super.viewDidLoad()
        tableviewLayout.isScrollEnabled = true
        scrollToLastRow()
    }
    override func viewWillAppear(_ animated: Bool) {
        self.tableviewLayout.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
      //only this is working   
      //but when i uncheck the adjust scroll view insets why it is not working
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return itemsArray.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {  
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel!.text = itemsArray[indexPath.row]
        return cell
    }
    func scrollToLastRow() {
        let indexPathrow = NSIndexPath(row: itemsArray.count - 1, section: 0)
        self.tableviewLayout.scrollToRow(at: indexPathrow as IndexPath , at: UITableViewScrollPosition.bottom, animated: true)
    }
}

scrollToLastRow()viewDidLoad方法中无法使用。您应该在viewDidAppear方法中使用它,并且可以正常工作。

最新更新