Skip to content

@nicwise /gist:3569920
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
RadioElement for MonoTouch.Dialog - autopops
public class RadioElement : StringElement {
public string Group;
internal int RadioIdx;
public bool PopOnSelect = false;
private bool ShouldDismiss = false;
public RadioElement (string caption, string group) : base (caption)
{
Group = group;
}
public RadioElement (string caption) : base (caption)
{
}
public RadioElement(string caption, bool popAutomatically, bool shouldDismiss = false) : base(caption)
{
PopOnSelect = popAutomatically;
ShouldDismiss = shouldDismiss;
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = base.GetCell (tv);
//var root = (RootElement) Parent.Parent;
var root = GetImmediateRootElement();
bool selected = false;
//if (root != null)
//{
if (!(root.group is RadioGroup))
throw new Exception ("The RootElement's Group is null or is not a RadioGroup");
selected = RadioIdx == ((RadioGroup)(root.group)).Selected;
//}
cell.Accessory = selected ? UITableViewCellAccessory.Checkmark : UITableViewCellAccessory.None;
cell.SelectionStyle = UITableViewCellSelectionStyle.Blue;
return cell;
}
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath indexPath)
{
var root = GetImmediateRootElement();
if (RadioIdx != root.RadioSelected){
var cell = tableView.CellAt (root.PathForRadio (root.RadioSelected));
if (cell != null)
cell.Accessory = UITableViewCellAccessory.None;
cell = tableView.CellAt (indexPath);
if (cell != null)
cell.Accessory = UITableViewCellAccessory.Checkmark;
root.RadioSelected = RadioIdx;
}
base.Selected (dvc, tableView, indexPath);
if (PopOnSelect)
{
if (ShouldDismiss)
{
dvc.NavigationController.DismissModalViewControllerAnimated(true);
} else {
dvc.NavigationController.PopViewControllerAnimated(true);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.