【问题标题】:Dismissing popup when RadioGroup Item Selected选择 RadioGroup 项目时关闭弹出窗口
【发布时间】:2011-12-02 23:24:30
【问题描述】:

现在在我的一些项目中使用了很棒的 MonoTouch.dialog 并且有一个问题。我有一个 RadioGroup 用于允许用户选择他的家庭状态,States 是一个字符串数组。

    public static RootElement CreateStates ()
    {
        return new RootElement ("State", new RadioGroup (0)) 
        {
            new Section ("Choose State")
            {
                from x in States
                   select (Element) new RadioElement (x) 
            }
        };
    }

这很好用,当我选择状态时,会出现弹出窗口并选择我的状态,但是我必须点击导航栏中的后退按钮才能返回主屏幕。当我选择一个选项时,有没有办法让该弹出窗口消失?不得不按后退按钮很烦人。还是我只是使用了错误的解决方案?

我的第一个想法是继承 RadioElement 并捕获选定的事件,但是我仍然不确定如何关闭自动选择弹出窗口?

【问题讨论】:

    标签: monotouch.dialog


    【解决方案1】:

    今天早上我遇到了同样的问题,我还想触发一个更改事件,以便在编辑数据时在对话框中添加一个“取消”按钮。这两项任务都要求您继承 RadioElement 并覆盖 Selected 方法 - 请注意额外的步骤,以确保如果用户单击已选择的项目,对话框不会关闭 - 如果您单击任何内容,即使它已被选中,它也会触发,所以我想防止这种情况发生 - 我的看起来像这样。

    public class MyRadioElement : RadioElement {
        // Pass the caption through to the base constructor.
        public MyRadioElement (string pCaption) : base(pCaption) {
        }
    
        // Fire an event when the selection changes.
        // I use this to flip a "dirty flag" further up stream.
        public override void Selected (
            DialogViewController pDialogViewController, 
            UITableView pTableView, NSIndexPath pIndexPath) {
            // Checking to see if the current cell is already "checked"
            // prevent the event from firing if the item is already selected.  
            if (GetActiveCell().Accessory.ToString().Equals(
                "Checkmark",StringComparison.InvariantCultureIgnoreCase)) {
                return;
            }
    
            base.Selected (pDialogViewController, pTableView, pIndexPath);
    
            // Is there an event mapped to our OnSelected event handler?
            var selected = OnSelected;
    
            // If yes, fire it.
            if (selected != null) {
                selected (this, EventArgs.Empty);
            }
    
            // Close the dialog.
            pDialogViewController.DeactivateController(true);
        }
    
        static public event EventHandler<EventArgs> OnSelected;
    }
    

    【讨论】:

    • 你就是男人!非常感谢。我很接近,这是如何关闭我错过的对话框。这正是我所需要的。
    • 太棒了。我想我也可以使用它:P。 russellj 您可以将此标记为已接受的答案吗?
    猜你喜欢
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多