开发者

Updating UI Manually

开发者 https://www.devze.com 2023-01-12 18:02 出处:网络
Is there a way to update 开发者_如何学JAVAUI manually? For example, I have a function which updates UI and execute some logic.

Is there a way to update 开发者_如何学JAVAUI manually? For example, I have a function which updates UI and execute some logic. After the UI update, it will execute some logic that will take a long time and update of UI has to be wait until the execution of logic is finished. Is there a way to update UI manually befor even the logic is even executed?

It seems that thread can be used in here. But Is there a way to solve this by not using thread? Also, using if thread can be used, what is the best practice?

Thanks!


Because the UI thread is the main thread of your app, it's generally not a good idea to process big operations on it because you froze your UI in the meantime (which is not user friendly).

The way you use thread depends on what you want to do, you can for example just use - (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg or you can create your own thread and be more specific.

Don't forget to call - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait if you want to do some changes on the UI from other thread.

You'll find all you need about thread programming in this guide from iOS Reference Library.

Hope this helps !


Are you thinking about a simple progress bar? If that is the case, then you can use something using NSApp (see the section under Managing the Event Loop) and use runModalForWindow: and runModalSession: These will allow you to open a progress panel, report on status and allow a method to cancel the operation.

Because the operation is modal, other UI elements will be deactivated until the panel is dismissed.

0

精彩评论

暂无评论...
验证码 换一张
取 消