与MonoTouch对话框的模态RadioGroup部分一起使用时,无法更新RootElement的文本

时间:2013-03-05 18:34:40

标签: xamarin.ios monotouch.dialog

我正在使用iPad创建MonoTouch 2.10.11应用,我希望MonoTouch.Dialog在表单上创建一些可编辑字段。其中一个字段将使用RadioGroup来允许用户从选项列表中进行选择。 M.T.D的默认行为是在现有表上显示选择列表表。这适用于iPhone布局,但在此iPad表单上,表格仅位于表单的小区域,导航栏在表单中间看起来很奇怪。我想将选择显示为全屏模式,用户将点击“返回”按钮返回上一个表单和所选项目。

我创建了一个新的RootElement后代类,如下所示:

public class ModalRootElement : RootElement 
{    
    public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
    {
        tableView.DeselectRow (path, false);
        UIViewController uIViewController = this.MakeViewController ();
        this.PrepareDialogViewController (uIViewController);
        dvc.PresentViewController (uIViewController, true, null);
    }

    protected override void PrepareDialogViewController(UIViewController dvc)
    {
        base.PrepareDialogViewController(dvc);

        UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
        button.Frame = new RectangleF (5, 5, 80, 20);
        button.SetTitle ("back", UIControlState.Normal);
        button.TouchUpInside += delegate {
            DialogViewController d = dvc as DialogViewController;

            (d.Root as ModalRootElement).TableView.ReloadData ();

            d.DeactivateController(true);
        };
        dvc.View.AddSubview (button);
    }
}

该表使用以下代码实现:

var _status = new ModalRootElement("Status", new RadioGroup("status", -1)) {
    (new Section() {
        new RadioElement("New", "status"),
        new RadioElement("In process", "status"),
        new RadioElement("Rejected", "status"),
        new RadioElement("Deferred", "status"),
        new RadioElement("Transferred", "status"),
        new RadioElement("Unknown", "status"),
        new RadioElement("Complete", "status")
    })
};

var _odom = new EntryElement ("Odometer", "current odom", "");
_odom.KeyboardType = UIKeyboardType.DecimalPad;
_odom.TextAlignment = UITextAlignment.Right;

var root = new RootElement ("back") {
    new Section("") {
        _status,
        _odom
    }
};

_dvc = new DialogViewController(root);
_nav = new UINavigationController (_dvc);
_nav.SetNavigationBarHidden (true, false);

当我运行应用程序时,我可以深入RadioGroup并进行选择。单击我添加到视图中的后退按钮时,模式视图将关闭,RadioSelected对象的ModalRootElement属性设置正确,但不显示文本。

如果我更改Selected()方法来调用dvc.ActivateController而非PresentViewController,则ModalRootElement会显示正确的文字,但RadioGroup表的大小错误。有没有办法让RootElement在您使用PresentViewController而不是ActivateController时显示正确的文字?

1 个答案:

答案 0 :(得分:0)

我认为您需要Root.Reload()调用。