Skip to content

Instantly share code, notes, and snippets.

@philcockfield
Created September 25, 2012 09:27
Show Gist options
  • Save philcockfield/3780833 to your computer and use it in GitHub Desktop.
Save philcockfield/3780833 to your computer and use it in GitHub Desktop.
MT.Dialog - RadioElement Problem
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
using System.Threading.Tasks;
namespace RadioButtonSample
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
// class-level declarations
UIWindow window;
Section rootSection;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
// Setup initial conditions.
window = new UIWindow(UIScreen.MainScreen.Bounds);
// Create root view controller.
var radioGroup = new RadioGroup(0);
var root = new RootElement("Title", radioGroup){
(rootSection = new Section("Foo"))
};
var dvc = new DialogViewController(root);
// WORKS: Add items synchronously.
// addRadios(3);
window.RootViewController = new UINavigationController(dvc);
window.MakeKeyAndVisible();
// FAILS: Add some items on a background thread.
// All items will be selected, and won't recieve click events.
Task.Factory.StartNew(() => {
BeginInvokeOnMainThread(() => addRadios(3));
});
// Finish up.
return true;
}
private void addRadios(int total)
{
for (int i = 0; i < total; i++)
addRadio("Item " + i);
}
private RadioElement addRadio(string caption)
{
var el = new RadioElement(caption);
rootSection.Add(el);
return el;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment