Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Runnable

macrumors newbie
Original poster
Aug 20, 2008
8
0
BadenWürtemberg, Germany
Hi @all,

i just wanted to add a subview to my main window from another thread.
like so:

Code:
AppDelegate.m
...
UpdateThread *t = [[UpdateThread alloc]init];
[t setWindow:window];
[t start];
...

Code:
UpdateThread#main
...
UILabel *l = [[UILabel alloc]initWithFrame:...];
//label's setup
[window addSubview:label];
...

Now i have the problem, that it does not work, there's no label visible after the thread terminates.
If i run the main's code in the Application's thread that calls applicationDidFinishLaunching it works properly.

can anyone please help me ?
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You can't access UI code from a second thread like this. You can use performSelectorOnMainThread from your secondary thread to make the update occur on the main thread.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.