使用DecelerationEnded与其他干扰回调(Using DecelerationEnded

2019-09-17 15:27发布

我试图使用DecelerationEnded回调与MT.Dialog元素“ 抽头 ”回调结合。 我不能让这两个在同一时间工作。

当DecelerationEnded回调被注释掉的“抽头”回调正常工作。 当它在评论的“抽头”回调没有得到触发了(而DecelerationEnded一样)。

当DecelerationEnded就是根的设置,然后“挖”工作的回调按钮上方移动,但是DecelerationEnded回调没有。 延迟回调设置直到viewWillAppear中也没有任何修复。

任何解决方案?

示例代码:

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");
    }
}

Answer 1:

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

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

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

如果你想挂钩到这一点,你需要继承现有的“源”类,并通过覆盖CreateSizingSource创建此,它应该提供你的类的新实例。 这是你需要重写,以提供相同的行为,但有自己的类的虚方法:

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

你可以只继承SizingSource和覆盖的方法那里的减速方法。

TweetStation有一个示例,演示如何做到这一点:它使用相同的事件,以确定何时从屏幕上删除未读的鸣叫的次数。



文章来源: Using DecelerationEnded interferes with other callbacks