590Adding an UIAlertView

Unlike other UIViews, UIAlertView does not need to be added to another view via addSubView. [myAlertView show] takes care of that.

Trivial, maybe. But I wasn't aware of it.

503UILabel and performSelectorOnMainThread

I've been struggling with that for a while... Why wouldn't my UILabel display it's updated text? The weird thing was, that I could update the text, as long as I called it from the same class.

But as I passed a reference to the UILabel to another class, and tried to set the text from there, it wouldn't show. Stranger still, I could see in the logs, that the value itself was updated, it only did not show on the screen.

I also tried to send a notification back to the class where I made the label, but again, no luck. Very strange, a directly called method would updated the label without problems, one called by the notification would not show the update.

What was I missing?

My first instinct was to check out [myLabel setNeedsDisplay];

I kind of worked. But only if I called from - for example a Button. It then updated the values of the UILabel. That's was a step forward, but not really satisfying; after all I'd like have updates on the UILabel whenever they arrived. And again, calling if from the notification also did not do the trick.

Then I found out, that it order for UILabels to visually update, the update command has to be called on the main loop! Yeah! And how to perfom and action on the main loop?

Yes, with performSelectorOnMainThread:

So, the solution it an anti-climax and here it is:


[myLabel performSelectorOnMainThread:@selector(setText:)withObject:myText waitUntilDone:NO];
//