设置UITableView的内容偏移在滚动时不起作用(Setting content offset of a UITableView not working when it's scroll

编程入门 行业动态 更新时间:2024-10-20 15:58:56
设置UITableView的内容偏移在滚动时不起作用(Setting content offset of a UITableView not working when it's scrolling)

这是我的代码

// 1 func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { scrollTableView() } // 2 @IBAction func buttonPressed() { scrollTableView() } // 3 func scrollTableView() { tableView.setContentOffset(CGPointZero, animated: false) // tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated:true) // does not work either }

即使调用方法1 (调用方法3),表视图也会继续自然滚动减速直到停止。 它并没有将自己定位在我想要的地方。

当表视图不滚动并且我通过按下按钮调用方法2时 ,它确实获得其内容偏移设置并且它位于应该的位置。

如何通过在方法1中调用来使其工作?

谢谢

Here's my code

// 1 func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { scrollTableView() } // 2 @IBAction func buttonPressed() { scrollTableView() } // 3 func scrollTableView() { tableView.setContentOffset(CGPointZero, animated: false) // tableView.scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated:true) // does not work either }

Even method 1 (who calls method 3) being called, the Table View continues its natural scrolling decelerating until it stops. It does not position itself where I want.

When the Table View is not scrolling and I call method 2 by pressing a button it does get its content offset set and it positions where it should.

How can I get it to work by being called in the method 1?

Thanks

最满意答案

如果我把你弄好了以下应该有效:

func scrollViewWillBeginDecelerating(scrollView: UIScrollView) { scrollTableView() }

if i got you right the following should work:

func scrollViewWillBeginDecelerating(scrollView: UIScrollView) { scrollTableView() }

更多推荐

本文发布于:2023-08-06 23:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456623.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   内容   Setting   UITableView   working

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!