Rule: dont change the UI on a thread. Ever.

I assume it's the Root.Add(buttons); which is the problem bit, so put
that in an InvokeOnMainThread call (most cocoa objects have this - if
you can't find it, new up a NSObject or NSString :) )

On Wed, Aug 17, 2011 at 14:03, efontana <[email protected]> wrote:
> I've got a DialogViewController, that's ViewDidAppear has this: (Note the
> commented out CreateScheduledTime/BeginInvokeOnMainThread and their closing
> brackets).
>
> If you run the code, as is, it works fine, you'll have 20 red buttons with
> white text.
>
> Uncomment out the Threading code (to make the UI more responsive) and boom,
> the colors
> and attributes are all messed up, bleeding through, etc.
>
> My question is (not really knowing Cocoa) what's going on here?   What are
> the rules of Threads
> and the UI?
>
> Thanks in advance.
>
>
> https://github.com/martinbowling/zxing.MonoTouch
> Root = new RootElement("Test Colored");
>
> //NSTimer.CreateScheduledTimer (TimeSpan.FromSeconds (0), delegate {
> //BeginInvokeOnMainThread (delegate
> //{
>
>    Section buttons = new Section("Buttons");
>    for (int i=0; i<20; i++)
>                        {
>    StyledStringElement se = new StyledStringElement(string.Format("Button
> {0}", i));
>    se.BackgroundColor = UIColor.Red;
>    se.TextColor = UIColor.White;
>
>    buttons.Add(se);
>  }
>
>  Root.Add(buttons);
> //});
> //});
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/MonoTouch-Dialog-DialogViewController-and-Threads-tp3749886p3749886.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to