c# - MonoTouch 对话框 - OnTap 不工作

标签 c# xamarin.ios monotouch.dialog

我正在为 MonoTouch.Dialog 使用反射 API。我想要完成的是,当用户从列表中选择一个项目时,我希望导航 Controller 返回。我不想强制用户单击某个项目,然后单击“返回”按钮返回。

但是,当尝试使用 OnTap 属性时,我的方法没有被执行。

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);

    var demo = new DemoClass();
    var context = new BindingContext(this, demo, "Some Demo");
    var controller = new DialogViewController(context.Root);
    var navController = new UINavigationController(controller);

    window.RootViewController = navController;
    window.MakeKeyAndVisible ();

    return true;
}

public void EnumSelected()
{
    InvokeOnMainThread(() =>
    {
        new UIAlertView("Dialog", "Enum Selected", null, "OK", null).Show();
    });
}

演示课

public enum DemoEnum
{
    SomeValue,
    AnotherValue,
    YetAnotherValue
}

public class DemoClass
{
    [OnTap("EnumSelected")]
    public DemoEnum SomeEnum;   
}

我知道如何使用导航 Controller 向后导航,但如果 OnTap 不工作,我就做不到那么远。我错过了什么吗?谁能看出我哪里出错了?

最佳答案

总之,你不能。

Enum(产生一个新的 RootController 和一堆 RadioElement)不能设置 OnTap,除非您全部手动完成。

https://github.com/migueldeicaza/MonoTouch.Dialog/blob/master/MonoTouch.Dialog/Reflect.cs#L337

尤其是这些位:

csection.Add (new RadioElement (ca != null ? ca.Caption : MakeCaption (fi.Name)));

element = new RootElement (caption, new RadioGroup (null, selected)) { csection };

没有触发器添加到 RadioElement。您需要将其更改为自动弹出表单 - 这需要一个新的/更改的 RadioElement

https://gist.github.com/3569920

(我不能声明此代码 - 它来自@escoz:https://github.com/escoz/MonoMobile.Forms)

因此,如果您使用内置的 MT.D,则无法执行此操作。如果您不介意维护自己的分支(或者提交一个拉取请求,这是我需要做的一些事情),那么这是一个相当不错的方法。

关于c# - MonoTouch 对话框 - OnTap 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141472/

相关文章:

c# - 从 Blazor 客户端调用 HttpClient.GetJsonAsync 返回(带数据),但随后超时

c# - 如何使一个复选框使所有复选框在 Listview C# 中被选中

xamarin.ios - Xamarin.iOS 应用程序何时需要 Register 属性?

ios5 - 从 MonoTouch 访问 iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification 详细信息

ios - 单点触控 : How to add/remove recipients balloons/bubbles for new message

iphone - Monotouch.Dialog - 设置后退按钮

c# - Fortran Dll导入

c# - 导入属性始终为空(MEF 导入问题)

visual-studio - Xamarin Visual Studio 无法在联网 MAC 上启动构建服务器激活

c# - MonoTouch.Dialog:部分中的 GlassButton