在我的视图控制器中,我有一个tableView
和加班我选择我的单元我的tableview
移动有点上行我不知道为什么会发生,我试图找出为什么会发生,但我什么也没得到。下面是我的代码,如果任何机构可以找出最新的错误,那么它会对我有帮助。`tableView`向上移动,同时选择单元格
奥特莱斯和变量:
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var headerView: UIView!
@IBOutlet var verticalSpaceConstraint: NSLayoutConstraint!
var lastVerticalOffset: CGFloat = 0
在ViewDidLoad:
tableView.contentInset = UIEdgeInsets(top: headerViewOriginalHeight, left: 0, bottom: 0, right: 0)
tableView.scrollIndicatorInsets = tableView.contentInset
lastVerticalOffset = tableView.contentOffset.y
...........
footerView.addSubview(footerLabel)
footerView.addSubview(footerRetryButton)
footerView.addSubview(activityIndicatorView)
self.tableView.tableFooterView = footerView
代表:
extension myViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reviewsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! TagDetailTableViewCell
..............................
return cell
}
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath == selectedIndexPath {
return UITableViewAutomaticDimension
} else {
return 100
}
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.beginUpdates()
if indexPath == selectedIndexPath {
selectedIndexPath = NSIndexPath()
}else {
selectedIndexPath = indexPath
}
tableView.endUpdates()
print("tableView ORIIGN Y AFETER ", tableView.contentOffset.y)
self.tableView.separatorStyle = .None
self.tableView.separatorStyle = .SingleLine
}
}
嗨,老兄,感谢响应,我使用'tableView.beginUpdates()'因为我改变了选择行和'self.automaticallyAdjustsScrollViewInsets的高度= FALSE '没有工作 –