- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 UIProgressView
,它使用 observedProgress
属性。然后我有一个观察到的 Progress
类型的变量。
现在我正在后台线程上写入 Core Data,然后更新 completedUnitCount
但它崩溃了。
代码如下:
var downloadProgress: Progress
init() {
downloadProgress = Progress()
}
func saveStuff() {
let stuff: [[String: Any]] = //some array of dictionaries
downloadProgress.totalUnitCount = Int64(stuff.count)
persistentContainer.performBackgroundTask { (context) in
for (index, item) in stuff.enumerated() {
// create items to be saved
context.perform {
do {
try context.save()
self.downloadProgress.completedUnitCont = Int64(index + 1)
} catch {
// handle error
}
}
}
}
}
所以它在 self.downloadProgress.completedUnitCont = Int64(index + 1)
行崩溃了。我在写这篇文章时意识到我还应该使用 weak
或 unowned
self 来停止保留周期,但是还有其他问题吗?
最佳答案
所有与 UI 相关的代码都必须从主线程执行,因此您必须将调用 self.downloadProgress.completedUnitCont = Int64(index + 1)
分派(dispatch)到主线程。像这样:
DispatchQueue.main.async {
self.downloadProgress.completedUnitCont = Int64(index + 1)
}
关于ios - 从后台线程更新 UIProgressView 进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49918267/
你好, 过去一周我一直在尝试解决如何在我的 viewController 中创建两个 progressView 的问题,但几乎没有成功。请参阅我附上的图表,作为我提出的问题的想法。 我正在创建一个带有
我似乎有与大多数人相反的问题。我在我的 UIProgressView(它被添加到我的单元格 View )上调用 setProgress。我没有动画调用它,但变化似乎是动画的,我似乎无法将其关闭。 我看
我有一个带有三个选项卡的选项卡栏应用程序。在我的第二个选项卡 View 中,我有一个 UIProgressView。我的 viewDidLoad 方法中有一个 NSTimer,它调用更新 Progre
我有一个 UIProgressView,我试图更改进度,但从未更新。我的“慢”操作是从 NSOperation/NSOperation 队列完成的,因此它应该是多线程的。 您是否已经经历过这种情况或者
我有一个 UIProgressView 作为 subview 添加到 self.view 中。我有一个已加载行的 UITableView。我需要每一行都有图像,但我不希望应用程序等待所有图像,因此我决
我有一个UIProgressView,我希望它看起来像这个图像。我已经设置了进度颜色,但不确定是否设置未进度颜色(图像中的白色)。 最佳答案 这是我自己在探索 UIProgressView 属性时发现
我正在使用 UIProgressView在我的应用程序中,现在运行良好。但我想让它更大(在高度方面)并将其着色为不同的颜色。 我正在寻找使用 PDColoredProgressView 为颜色,并更改
我的新应用程序有小问题。一开始我以为这只是线程的问题,但现在我觉得我必须重写一半的代码来修复它。在此之前,也许你会帮助我:) 现在我正在编写将从服务器下载东西的应用程序。我们有两个对象:MainVie
我正在使用 CKOperation 将记录数组保存在云套件中,如下所示并使用进度 View 显示进度。 let saveOperation = CKModifyRecordsOperation
我做了一些 HTTP 请求,在收到 HTTP 响应时设置类属性,并使用 willSet 更新进度条值。进度条动画仅运行一次。 var data: CompatibilityData? { di
我使用 Xcode 10 和 Swift 4.2 在 UIViewController 的 viewDidload() 中,我声明了一个观察者: override func viewDidLoad()
我目前正在开发一个基于测验的 iOS 应用程序。我想添加一个进度条,根据问题的回答是否正确来改变颜色。根据回答是否正确,我只想将该间隔更改为绿色/红色,而不是整个条形。我的进度条有 50 个间隔。我尝
如果我的术语不正确,我深表歉意 - 我学习 Objective C 才几天,所以我还是有点陌生。 我有一个 ViewController,它有一个进度条 (UIProgressView),它使用
我有一个 UIProgressView 我想在我的 GLKViewController 上运行,而其余代码正在由 iOS 加载。我已将 UIProgressView 放入我的“viewDidLoad”
我有一个以编程方式添加到 Storyboard View 的 UIProgressView 以及将其放置在导航栏底部的约束。有一个菜单,打开时会暂时隐藏导航栏,关闭时会再次取消隐藏。打开和关闭此菜单后
我使用 asihttprequest 下载多个文件,我想知道如何在下载完成后通过正确的请求删除关联的 UIProgressview。 NSMutableArray *contentArray 包含 A
有没有办法让 progressTintColor 变成渐变色?具体来说,我想让它成为从绿色到红色的渐变色 - 标准温度模式。 添加子层不起作用,因为它把层放在 View “后面”: CAGradien
我正在将进度设置为 UIProgressView : [recordingProgress setProgress:seconds/600 animated:YES]; 该行位于一个不断重复的计时器中
遵循 this question 中概述的答案,我设法让 UIProgressView 有点工作,但它似乎在它应该之前完成更新(即栏“填满”)。 我尝试添加一些日志语句来查看发生了什么: float
我有一个从服务器下载图片的应用程序。我想向用户展示进度。我已经在苹果文档上阅读了有关 UIProgressView 的内容,并在该网站上阅读了许多答案,但我无法让它工作。这是我的代码在我的 viewD
我是一名优秀的程序员,十分优秀!