Solved

Updating UI Manually

Posted on 2010-08-24
3
842 Views
Last Modified: 2013-11-25
Hi,

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!
0
Comment
Question by:privateson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33514471
In this thread:
http://www.experts-exchange.com/Apple/Programming/Objective-C/Q_26411565.html?sfQueryTermInfo=1+10+30+setneedsdisplai

I've told to use
[theView setNeedsDisplay:YES];

in case you need to update the view. You can do it from the main thread.
Do you understand this way? Maybe, I do not understand your questions?

About the threads. Yes, any long operation in any language, for any device, should be launched in a separate thread. In iOS you can use POSIX threads and NSThread.
iOS Reference Library. Thread Management
http://developer.apple.com/iphone/library/documentation/cocoa/conceptual/Multithreading/CreatingThreads/CreatingThreads.html

I'd say to use NSThread. Here are two simple tutorials:
http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/
http://www.eigo.co.uk/Programming-threaded-processes-in-iPhone.aspx

The idea is simple. You create new thread:
[NSThread detachNewThreadSelector:@selector(threadMethod) toTarget:self withObject:nil];
The thread method should be like that:
- (void)threadMethod {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      //Here is the code.
      [pool release];
}

If you need to do something in the main thread from this new thread:
[self performSelectorOnMainThread:@selector(UpdateUIMethod) withObject:nil waitUntilDone:false];
In that method (it will be called in the main thread), you can update the UI.

You can try:
[theView performSelectorOnMainThread:@selector(setNeedsDisplay:YES) withObject:myText waitUntilDone:NO];

(I just wrote it here without testing, but it gives an idea)




0
 

Author Closing Comment

by:privateson
ID: 33532600
thanks!
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33532638
You are welcome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ vs C compilers 13 164
Unable to start eclipse ? 17 163
How to translate this 2-line while loop into C from Perl? 8 135
Assignment from incompatible pointer type? 2 37
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
CocoaPods is the best way to manage library dependencies in iOS and OS X projects. By using cocoa pods there is no need of downloading the code from github and copying to your project. There are plenty of open source libraries now available with C…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question