Xamarin.ios 与带有MonoTouch对话框的modal RadioGroup节一起使用时,无法更新根元素的文本
我正在使用Xamarin.ios 与带有MonoTouch对话框的modal RadioGroup节一起使用时,无法更新根元素的文本,xamarin.ios,monotouch.dialog,Xamarin.ios,Monotouch.dialog,我正在使用MonoTouch 2.10.11创建一个iPad应用程序,我想要MonoTouch.Dialog在表单上创建一些可编辑字段。其中一个字段将使用RadioGroup允许用户从选项列表中进行选择。M.T.D的默认行为是在现有表上显示选择列表表。这对于iPhone布局非常有效,但是在这个iPad表单上,表格只在表单的一小部分,导航栏在表单中间看起来很奇怪。我想将选择显示为全屏模式,用户将点击“后退”按钮,返回上一个表单和所选项目 我创建了一个新的RootElement子类,如下所示: pu
MonoTouch 2.10.11
创建一个iPad
应用程序,我想要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
并进行选择。当我单击添加到视图中的后退按钮时,模式视图将关闭,ModalRootElement
对象的RadioSelected
属性设置正确,但文本不会显示
如果我将
Selected()
方法更改为调用dvc.ActivateController
而不是PresentViewController
,则ModalRootElement
显示正确的文本,但RadioGroup
表的大小不正确。当您使用PresentViewController
而不是ActivateController
时,有没有办法让RootElement
显示正确的文本?我想您需要一个Root.Reload()调用。这不是一个真正的答案,所以我将其作为注释。您是否尝试过按视图控制器?然后,您可以稍后PopViewController
。此外,您还可以从RadioElement类继承创建自己的RadioElement
。这将允许您拥有一个事件,您可以连接到该事件,并在上一个屏幕上设置radiogroup中文本的索引。我希望这是有道理的。