我正在尝试使用减速结束与 ' 一起回调Tapped' MT.Dialog 元素上的回调。我无法让两者同时工作。
当 DecelerationEnded 回调被注释掉时,“点击”回调将起作用。当它被注释时,“tapped”回调将不再被触发(而 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");
}
}
在 MonoTouch 中,您可以使用 C# 风格的回调或 Objective-C 风格的回调,但它们不能混合在一起:
http://docs.xamarin.com/ios/advanced_topics/api_design#Delegates http://docs.xamarin.com/ios/advanced_topics/api_design#Delegates
在内部,MonoTouch.Dialog 库通过提供处理所有事件的完整子类来实现其功能。如果您使用 C# 语法,它将用代理替换内置处理程序,在本例中,代理仅响应 DecelerationEnded。
如果你想连接到这个,你需要子类化现有的“Source”类,并通过重写 CreateSizingSource 创建它,它应该提供你的类的一个新实例。这是您需要重写的虚拟方法,以提供相同的行为,但使用您自己的类:
public virtual Source CreateSizingSource (bool unevenRows)
{
return unevenRows ? new SizingSource (this) : new Source (this);
}
您只需子类化 SizingSource 并重写其中的减速方法即可。
TweetStation 有一个示例展示了如何完成此操作:它使用相同的事件来确定何时从屏幕上删除未读推文的数量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)