我有一个使用自定义tableview单元格的tableview。自定义tableviewcell按钮事件发射多次
当我们点击按钮时,事件被激发多次,但不是所有的时间。
我观察到,细胞是从来没有在下面的代码空在我的tableview
var cell = (MyCustomCell)tableView.DequeueReusableCell (MyCustomCell.Key);
我使用动态原型,我的tableview
我觉得这是与细胞可重用性和按钮的问题,甚至结合但我无法弄清楚它为什么会发生,以及如何解决它?
更新
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
//Getting the value from arrary as data source here
var cell = (MyCustomCell)tableView.DequeueReusableCell (MyCustomCell.Key);
if (cell == null) {
cell = MyCustomCell.Create();
}
button.TouchUpInside -= yourHandler;
button.TouchUpInside += yourHandler;
//assigning the values to labels
return cell;
}
凡被我删除按钮事件并添加它,然后它不应该多次
发布您的cellForRowAtIndexPath方法,以及选中您的表格视图单元格的连接检查器的屏幕截图。 –
@DuncanC - 请找到更新 – Sharath
我不知道我能提供多少帮助。我完全不熟悉Xamarin或C#。 “GetCell”是“cellForRowAtIndexPath”的Xamarin等价物吗?你需要发布“绑定事件”的代码。请记住,如果没有可用的再生细胞,则DequeueReusableCell方法仅创建一个新的细胞。一旦显示了表格视图,你通常会得到一个已经配置好代码的循环单元。 (并且如果您的单元配置包括向按钮添加目标/操作,那么您可能会在每次回收单元时添加额外的目标/操作。 –