gpt4 book ai didi

ios - 在 DialogViewController 中滚动破坏了单元格点击事件

转载 作者:行者123 更新时间:2023-11-29 03:38:05 25 4
gpt4 key购买 nike

我正在尝试使用 MTD 框架在 Xamarin.IOS 中实现无限滚动。为了实现这一点,我从 TableView 属性处理了 Scrolled 事件,但是一旦我为该事件定义了处理程序,我的元素(都是 StyledStringElement)的所有 Taped 事件就会停止工作,处理程序将不再被调用。即使我稍后在我的代码中取消订阅该事件,只要我“触摸”Scrolled 事件,单元格 Tapped 就会中断。

这是我处理滚动事件的方法:

_root_ViewController = new DialogViewController(_rootElement);
_root_ViewController.TableView.Scrolled += TableView_Scrolled;

以下是我创建单元格的方法:

StyledStringElement newCell = new StyledStringElement(item.Name)
{Accessory = UITableViewCellAccessory.DisclosureIndicator };
newCell.Tapped+=()=> _nav.PushViewController(getDetailView(item.Name, item.ID), true);

有什么想法吗?如果这是错误或不应该做的事情,那么实现无限滚动的正确方法是什么?我必须检测到用户正在接近表格底部以“预取”下一页。

谢谢。

最佳答案

问题在于 UIKit 的基于事件的系统和基于 native 委托(delegate)的系统是互斥的。这意味着如果您使用事件,则不能使用委托(delegate),如果您使用委托(delegate),则不能使用事件。

您正在访问的 TableView 恰好有一个由 MonoTouch.Dialog 设置的委托(delegate)处理程序,因此当您提供事件时,它会重置其内部处理。

对此的唯一解决方案是对内部 Tableview 委托(delegate)进行子类化,并将其作为您的委托(delegate)来拦截这些消息。

关于ios - 在 DialogViewController 中滚动破坏了单元格点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18856065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com