2017-10-25 7 views
0

Xamarin에서 여러 이벤트 처리기가 할당 된 셀에서 UIButton 문제가 발생합니다. 하나의 이벤트 핸들러 만 지정되도록하는 방법이 있습니까? tableview 또는 collectionview를 다시로드 할 때 해당 셀의 내용이 모두 해제되거나 재설정 될 것이라고 가정했습니다. 그게 잘못된거야?Xamarin UIButton에 여러 이벤트 처리기가 있습니다.

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); 
    } 

답변

0

귀하의 FilterCollectionCell : 여기

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; 
     } 

내가 셀 뷰 컨트롤러의 버튼에 이벤트 처리기를 추가하는 코드는 다음과 같습니다 I 설정이 대리인의 셀 어디 여기

입니다 생성은 셀에 이벤트 적용을 처리해야하므로 셀이 재사용 될 때마다 GetCell 메서드 내에서 매번 새 이벤트를 추가하지 않습니다.

그렇지 않으면 모든 UButtons '목표를 검색하고 그들에게 셀이 요청 될 때마다 제거 할 수 있습니다

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

내가 FilterCollectionCell에 적용 이벤트를 처리 할 방법을? – linuxer

+0

@SushiHanover 어떤 지침이 있습니까? – linuxer

관련 문제