Ios Xamarin UIButton具有多个事件处理程序

Ios Xamarin UIButton具有多个事件处理程序,ios,events,xamarin,uibutton,handler,Ios,Events,Xamarin,Uibutton,Handler,我遇到了一个问题,单元格中的UIButtons在Xamarin中分配了多个事件处理程序。有没有办法确保只分配一个事件处理程序?我假设在重新加载tableview或collectionview时,这些单元格中的任何内容都将被释放/重置。这不对吗 下面是我在委托中设置单元格的位置: public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) {

我遇到了一个问题,单元格中的UIButtons在Xamarin中分配了多个事件处理程序。有没有办法确保只分配一个事件处理程序?我假设在重新加载tableview或collectionview时,这些单元格中的任何内容都将被释放/重置。这不对吗

下面是我在委托中设置单元格的位置:

public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            EventHandler clickTarget = (sender, e) =>
            {
                if (this.parantController.showCategories)
                {
                    this.parantController.apiCallGetBusinessesIndustries(this.parantController.businessesCategoriesResponseModel.business_categories[indexPath.Row].id);
                    this.parantController.showIndustries = true;
                    this.parantController.showCategories = false;
                }
                else  if (this.parantController.showIndustries)
                {
                    this.parantController.apiCallGetBusinessessList("", this.parantController.businessesIndustriesResponseModel.business_industries[indexPath.Row].id);
                    this.parantController.filterView.Hidden = true;
                    this.parantController.showVerticalList = false;
                    this.parantController.showIndustries = false;
                    this.parantController.clearAll = true;
                    this.parantController.filterCollectionView.ReloadData();
                    this.parantController.clearAll = false;
                    //this.parantController.showCategories = true;
                }
            };

            var cell = (FilterCollectionCell)collectionView.DequeueReusableCell("filterCollectionCell", indexPath);
            if (this.parantController.businessesCategoriesResponseModel.business_categories != null && !this.parantController.showIndustries)
            {
                cell.updateCell(false, this.parantController.businessesCategoriesResponseModel.business_categories[indexPath.Row].name, clickTarget);
            }
            if (this.parantController.showIndustries)
            {
                cell.updateCell(false, this.parantController.businessesIndustriesResponseModel.business_industries[indexPath.Row].name, clickTarget);
            }

            return cell;
        }
下面是我将事件处理程序添加到单元视图控制器中按钮的代码:

public void updateCell(Boolean selectedFilterType, string title, EventHandler clickHandler) {

        btnFilter.RemoveTarget(this, null, UIControlEvent.AllEvents);

        btnFilter.AddTarget(clickHandler, UIControlEvent.TouchUpInside);// = handlerToUse;

        this.btnFilter.SetTitle(title, UIControlState.Normal);
    }

您的
FilterCollectionCell
创建应处理将事件应用到单元格的操作,以便在重用单元格时,您不会每次在
GetCell
方法中追加新事件

否则,您可以检索所有ubutton的目标,并在每次请求单元格时删除它们:

foreach (var target in button.AllTargets)
{
    button.RemoveTarget(target, null, UIControlEvent.AllTouchEvents);
}

我将如何处理在FilterCollectionCell中应用事件?@sushinhan是否有任何指导?