gpt4 book ai didi

iOS - 延迟向 UITableView 添加行的最佳方法?

转载 作者:行者123 更新时间:2023-11-30 13:31:45 25 4
gpt4 key购买 nike

我正在尝试制作一个与游戏非常相似的iOS Lifeline

游戏看起来就像只是一个 TableView ,在延迟后插入了一行。

我已经成功插入这样的行

 for obj in array {
self.dialogue.append(obj)
self.tableView.beginUpdates()
self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()
}}

*注意 self.dialogue 是我的 TableView 的数据源。

但是,例如,我不知道如何在添加新行之间添加延迟

->插入行->等待3秒->插入另一行

我怎样才能像游戏中那样做到这一点?

最佳答案

您可以实现单独的方法或 block 来插入行,并从 for 循环内部延迟调用它。例如

var dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(1.0 * Double(NSEC_PER_SEC))) 

for obj in array {
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.dialogue.append(obj)
self.tableView.beginUpdates()
self.tableView.insertRowsAtIndexPaths([NSIndexPath(forRow: 0, inSection: 0)], withRowAnimation: UITableViewRowAnimation.Fade)
self.tableView.endUpdates()
})
}}

关于iOS - 延迟向 UITableView 添加行的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36500408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com