简体   繁体   English

UIProgressView在后台线程中更新

[英]UIProgressView update in background thread

I have to call function calculating some thing on MainThread . 我必须调用函数在MainThread上计算一些东西。 When calculation process running, I can call UIProgressView to update UI. 当计算过程运行时,我可以调用UIProgressView来更新UI。

When I just call update function, it's working but update UI at last 当我只调用更新功能时,它正在工作,但最后更新了用户界面

I use performSelectorInBackground calling update function and it's work fine . 我使用performSelectorInBackground调用更新功能,它工作正常

Why use performSelectorInBackground can work 为什么使用performSelectorInBackground可以工作

click here to show GIF 点击此处显示GIF

I have seen this What's happen if control UI by performSelectorInBackground? 我已经看到了, 如果通过performSelectorInBackground控制UI会发生什么? , but it not explain why performSelectorInBackground working. ,但没有说明为什么performSelectorInBackground工作。

the sample code 示例代码
https://github.com/g78101/progressViewTest https://github.com/g78101/progressViewTest

I find some soultion 我觉得有些伤心

From the doc : 从文档
[myObj performSelectorInBackground:@selector(doSomething) withObject:nil]; [myObj performSelectorInBackground:@selector(doSomething)withObject:nil];
The effect of calling this method is the same as if you called the detachNewThreadSelector:toTarget:withObject: method of NSThread with the current object, selector, and parameter object as parameters. 调用此方法的效果与使用当前对象,选择器和参数对象作为参数调用NSThread的detachNewThreadSelector:toTarget:withObject:方法的效果相同。

BackgroundThread just change the UI value, update UI is runnning on mainThread. BackgroundThread只是更改UI值,更新UI正在mainThread上运行。

Just NSThrad can work 只是NSThrad可以工作

I think the reason is framework of NSThrad simpler than GCDs 我认为原因是NSThrad的框架比GCD更简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM