使用 DecelerationEnded 会干扰其他回调 [英] Using DecelerationEnded interferes with other callbacks

查看:28
本文介绍了使用 DecelerationEnded 会干扰其他回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 DecelerationEnded 回调与 MT.Dialog 元素上的Tapped"回调结合使用.我不能让两者同时工作.

I'm trying to use the DecelerationEnded callback in conjunction with 'Tapped' callbacks on MT.Dialog elements. I can't get the two to work at the same time.

当 DecelerationEnded 回调被注释掉时,tapped"回调起作用.当它被评论时,'tapped' 回调不再被触发(而 DecelerationEnded 会).

When the DecelerationEnded callback is commented out, the 'tapped' callbacks work. When it's commented in, the 'tapped' callbacks don't get triggered anymore (whereas DecelerationEnded does).

当 DecelerationEnded 调用移到 Root 设置上方时,按钮点击"回调起作用,但 DecelerationEnded 回调不起作用.将回调设置延迟到 ViewWillAppear 也不会解决任何问题.

When the DecelerationEnded call is moved above the setting of the Root, then the button 'tapped' callbacks work, but the DecelerationEnded callback doesn't. Delaying the callback setup until ViewWillAppear also doesn't fix anything.

有什么解决办法吗?

示例代码:

public class TestController : DialogViewController
{
    public TestController () : base(UITableViewStyle.Plain, null, true)
    {
        // Create list of 20 buttons.
        Section s = new Section();

        for (int i = 0; i < 20; i++ )
        {
            s.Add(new StringElement("test " + i, () => {
                Console.WriteLine("Tapped"); // Tapped callback.
            }));
        }

        Root = new RootElement("Test") {s};

        // The following line causes all the "tapped" handlers to not work.
        this.TableView.DecelerationEnded += HandleDecelerationEnded;
    }

    void HandleDecelerationEnded (object sender, EventArgs e)
    {
        Console.WriteLine ("Deceleration Ended");
    }
}

推荐答案

在 MonoTouch 中,您可以使用 C# 风格的回调或 Objective-C 风格的回调,但它们不能混合在一起:

In MonoTouch you can use either the C# style of callbacks or the Objective-C style of callbacks, but they can not be mixed together:

http://docs.xamarin.com/ios/advanced_topics/api_design#Delegates

MonoTouch.Dialog 库在内部通过提供处理所有事件的完整子类来实现其功能.如果您使用 C# 语法,它会将内置处理程序替换为代理,在这种情况下,该代理仅响应 DecelerationEnded.

Internally the MonoTouch.Dialog library implements its features by providing a full subclass that handles all of the events. If you use the C# syntax, it replaces the built-in handler with a proxy that in this case, merely responds to DecelerationEnded.

如果你想连接到这个,你需要继承现有的Source"类,并通过覆盖 CreateSizingSource 来创建它,它应该提供你的类的一个新实例.这是您需要重写以提供相同行为但具有您自己的类的虚拟方法:

If you want to hook up to this, you need to subclass the existing "Source" class, and create this by overriding the CreateSizingSource, and it should provide a new instance of your class. This is the virtual method that you need to override to provide the same behavior but with your own classes:

public virtual Source CreateSizingSource (bool unevenRows)
{
    return unevenRows ? new SizingSource (this) : new Source (this);
}

您可以子类化 SizingSource 并覆盖那里的方法以用于减速方法.

You can just subclass SizingSource and override the method there for the deceleration method.

TweetStation 有一个示例展示了这是如何完成的:它使用相同的事件来确定何时从屏幕上删除未读推文的数量.

TweetStation has a sample that shows how this is done: it uses the same event to determine when to remove the number of unread tweets from the screen.

这篇关于使用 DecelerationEnded 会干扰其他回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆