David Gao
David Gao

Reputation: 906

Updating UI Manually

Is there a way to update UI 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!

Upvotes: 0

Views: 1038

Answers (2)

Ermiar
Ermiar

Reputation: 1077

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 !

Upvotes: 1

Steven Noyes
Steven Noyes

Reputation: 1549

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.

Upvotes: 0

Related Questions