Uitableview TableView.DeceloseRow未触发自定义元素的取消选择事件
我可能在这里遗漏了什么,但是,当我手动取消选择一行时,我无法在我的自定义Uitableview TableView.DeceloseRow未触发自定义元素的取消选择事件,uitableview,xamarin.ios,monotouch.dialog,Uitableview,Xamarin.ios,Monotouch.dialog,我可能在这里遗漏了什么,但是,当我手动取消选择一行时,我无法在我的自定义元素类上触发取消选择事件。我正在覆盖单元格以进行一些自定义绘图,并希望在选中/取消选中单元格时更改字体的颜色 下面详细介绍了实际问题的工作示例 public class TestViewController : DialogViewController { public TestViewController () : base(UITableViewStyle.Plain, null, true) {
元素
类上触发取消选择
事件。我正在覆盖单元格以进行一些自定义绘图,并希望在选中/取消选中单元格时更改字体的颜色
下面详细介绍了实际问题的工作示例
public class TestViewController : DialogViewController
{
public TestViewController () : base(UITableViewStyle.Plain, null, true)
{
Root = new RootElement(null);
var section = new Section();
for (int i = 0; i <= 10; i++)
{
var element = new MyCustomElement();
element.Tapped += (dvc, tableView, indexPath) => {
var sheet = new UIActionSheet("", null, "Cancel", null, null);
sheet.Dismissed += delegate(object sender, UIButtonEventArgs e) {
tableView.DeselectRow(indexPath, false);
};
sheet.ShowInView(View);
};
section.Add (element);
}
Root.Add (section);
}
}
public class MyCustomElement : Element, IElementSizing {
static NSString mKey = new NSString ("MyCustomElement");
public MyCustomElement () : base ("")
{
}
public MyCustomElement (Action<DialogViewController,UITableView,NSIndexPath> tapped) : base ("")
{
Tapped += tapped;
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell (mKey);
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, mKey);
return cell;
}
public float GetHeight (UITableView tableView, NSIndexPath indexPath)
{
return 65;
}
public event Action<DialogViewController, UITableView, NSIndexPath> Tapped;
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
Console.WriteLine("Selected!");
if (Tapped != null)
Tapped (dvc, tableView, path);
}
public override void Deselected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
// does not trigger when deselect manually invoked
Console.WriteLine("Deselected!");
base.Deselected (dvc, tableView, path);
}
}
公共类TestViewController:DialogViewController
{
公共TestViewController():基(UITableViewStyle.Plain,null,true)
{
Root=新的RootElement(null);
var节=新节();
对于(int i=0;i{
var sheet=新UIActionSheet(“,null,“Cancel”,null,null);
sheet.Disposed+=委托(对象发送方,UIButtonEventArgs e){
取消选择行(indexPath,false);
};
表.ShowInView(视图);
};
第节.添加(要素);
}
根。添加(节);
}
}
公共类MyCustomElement:Element,IElementSizing{
静态NSString mKey=新NSString(“MyCustomElement”);
公共MyCustomElement():基(“”)
{
}
公共MyCustomElement(操作):基(“”)
{
抽头+=抽头;
}
公用覆盖UITableViewCell GetCell(UITableView电视)
{
var cell=tv.DequeueReusableCell(mKey);
if(单元格==null)
单元格=新的UITableViewCell(UITableViewCellStyle.Default,mKey);
返回单元;
}
公共浮点GetHeight(UITableView tableView,NSIndexPath indexPath)
{
返回65;
}
公共事件行动;
已选择公共覆盖无效(DialogViewController dvc、UITableView tableView、NSIndexPath路径)
{
Console.WriteLine(“已选择!”);
如果(抽头!=null)
点击(dvc、表视图、路径);
}
取消选择公共覆盖无效(DialogViewController dvc、UITableView tableView、NSIndexPath路径)
{
//手动调用取消选择时不触发
Console.WriteLine(“取消选择!”);
取消选择(dvc、表视图、路径);
}
}
我还尝试过覆盖对话框ViewController
本身上的取消选择
事件,甚至创建了一个自定义源
并覆盖其中的行取消选择
事件,但它仍然没有被触发。我触发它的唯一方法是移除点击
处理程序并选择一个差异不同的细胞
为了解决这个问题,我目前正在做的是在调用
DeselectRow
后手动强制元素更新自身,但是,我想知道它为什么没有触发。您没有收到Deselected事件,因为deselectRowAtIndexPath:animated:method不会导致代理接收tableView:didDeselectRowAtIndexPath:message,它也不会向观察者发送UITableViewSelectionDidChangeNotification通知,并且调用此方法不会导致任何滚动到已取消选择的行。似乎有点限制,您不这样认为吗?正如您从所示示例中看到的,有一些明显的示例表明您希望取消选择项目in手动创建列表视图。是否有其他方法可以取消选择列表中将发送通知的项目?其ios限制,而不是monotouchdialog。出现时tableView:DidDeceloseRowIndexPath:monotouch dialog称为目标元素的取消选择事件,但调用tableView.DeceloseRow(indexPath,false)tablesource未接收tableView:DidDeceloseRowatingIndexPath:和Decelected event not called。您可以使用函数删除选择并调用元素的Decelected event。我不确定是否理解您所说的“出现时tableView:DidDeceloseRowatingIndexPath:monotouch对话框调用目标元素的Decelected event”是什么意思?decelerow
在幕后调用本机didecelerowatinexpath
。