Ios 使用ScrollToRowatineXpath在tableView中动态滚动

Ios 使用ScrollToRowatineXpath在tableView中动态滚动,ios,swift,uitableview,scroll,Ios,Swift,Uitableview,Scroll,我想直观地浏览我的整个tableView。我尝试了以下操作,但它似乎没有执行滚动。相反,它只是在循环中运行。我插入了一个dispatch\u async(dispatch\u get\u main\u queue())语句,认为这样可以确保在继续之前刷新视图,但运气不好 我做错了什么 func scrollThroughTable() { for sectionNum in 0..<tableView.numberOfSections() { for rowNum

我想直观地浏览我的整个tableView。我尝试了以下操作,但它似乎没有执行滚动。相反,它只是在循环中运行。我插入了一个dispatch\u async(dispatch\u get\u main\u queue())语句,认为这样可以确保在继续之前刷新视图,但运气不好

我做错了什么

func scrollThroughTable() {
    for sectionNum in 0..<tableView.numberOfSections() {
        for rowNum in 0..<tableView.numberOfRowsInSection(sectionNum) {

            let indexPath = NSIndexPath(forRow: rowNum, inSection: sectionNum)
            var cellTemp = self.tableView.cellForRowAtIndexPath(indexPath)
            if cellTemp == nil {
                    dispatch_async(dispatch_get_main_queue()) {
                    self.tableView.scrollToRowAtIndexPath(indexPath!, atScrollPosition: .Top, animated: true)
                    self.tableView.reloadData()
                    }
            }
        }
    }
}
func滚动浏览表(){

对于0..中的sectionNum,我找到了一个解决方案。只需在动画中使用ScrollToRowatineXpath()。为此,我必须创建一个getIndexPath()函数,以确定我要滚动的位置。如果我将tableView的最后一个元素传递给它,它的效果或多或少与滚动整个表相同

如果您想让它发生得更慢,滚动效果更好,请将其包装在UIView.animateWithDuration()中,并使用“duration”进行播放。如果您想在其完成块中播放更多动画,您甚至可以执行更多动画。(无需设置不可靠的睡眠计时器等)

func animateReminderInserted(toDoItem: ReminderWrapper) {
    if let definiteIndexPath = indexPathDelegate.getIndexPath(toDoItem) {
        self.tableView.scrollToRowAtIndexPath(definiteIndexPath, atScrollPosition: .Middle, animated: true)
    }
}