使用DecelerationEnded会干扰其他callback

我试图使用DecelerationEndedcallback与MT.Dialog元素上的“Tapped”callback一起使用。 我不能让这两个人同时工作。

当DecelerationEndedcallback被注释掉时,“tapped”callback工作。 当它被注释时,“tapped”callback不会被触发(而DecelerationEnded不会)。

当DecelerationEnded调用移动到Root的设置之上时,button“tapped”的callback工作,但是DecelerationEndedcallback没有。 延迟callback设置,直到ViewWillAppear也不能解决任何问题。

任何解决scheme

示例代码:

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#风格的callback或Objective-C风格的callback,但不能将它们混合在一起:

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

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

如果你想连接到这个,你需要inheritance现有的“Source”类,并通过重写CreateSizingSource来创build它,它应该提供一个新的类的实例。 这是您需要重写的虚拟方法,以提供与您自己的类相同的行为:

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

您可以inheritanceSizingSource的子类并覆盖减速方法。

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