2013-06-03 1 views
0

DetailDisclosureButton 대신 사용자 정의 셀 액세서리를 사용하는 경우 AccessoryButtonTapped 이벤트를 오래 사용할 수 없습니다 ... 사용자 정의 셀 액세서리 (예 : UIButton 세트 셀에 대한 AccessoryView로) 선택된 행과 섹션을 카운트하는 NSIndexPath를 가져올 수 있습니까?사용자 정의 셀 액세서리를 사용하는 모노 터치 - 선택된 행을 알려주는 방법

image = UIImage.FromFile ("Images/checkmark.png"); 
    lockButton = new UIButton(UIButtonType.Custom); 
    frame = new RectangleF(0f, 0f, 25f, 25f); 


    lockButton.Frame = frame; 
    lockButton.SetBackgroundImage(image, UIControlState.Normal); 
    lockButton.TouchUpInside += (sender, e) => 
    { 
     try{ 
      int i =0; 
      foreach(UIView sv in cell.Subviews) 
      { 
       if(cell.Subviews[i] is UITableView) 
        ; 
      } 
     } 
     catch 
     { 

     } 
    }; 


    if (sourceType == TableSoureType.Collections && collGroup [indexPath.Section].LocationEntity [indexPath.Row].CollectionStatus.ToLower() != "open") { 
     cell.TextLabel.TextColor = UIColor.Gray; 
     cell.AccessoryView = lockButton; 
    } 
    else if(sourceType == TableSoureType.Collections && collGroup [indexPath.Section].LocationEntity [indexPath.Row].CollectedToday) { 
     cell.TextLabel.TextColor = UIColor.Black; 
     cell.AccessoryView = lockButton; 
    } 
    else 
    { 
     cell.TextLabel.TextColor = UIColor.Black; 
     cell.Accessory = UITableViewCellAccessory.DetailDisclosureButton; 
     } 

이 새로운 게시물에 대한 원인이 될 수 있지만, 나는 또한 내가 시뮬레이터에있는 버튼 응용 프로그램이 종료를 클릭하여 문제를 가지고는 - 나는의 선언을 이동 있도록이 쓰레기 수거 문제가 될 수 있음을 이해 내 단추, 이미지 및 프레임을 클래스 수준에서 사용하지 마십시오.

그래서 나는 두 가지 문제가 있습니다

1 - 내가 얻을 일단 TouchUpInside 이벤트가 올바르게 내가 그 이벤트가 발생할 때 어느 셀이 선택되었다 알아낼 어떻게 작동?

2 - TouchUpInside 이벤트가 시뮬레이터에서 충돌을 일으키지 않고 실행되도록하는 방법 - 가비지 수집 문제를 이해함에 따라 - 나는 크래시가 장치 자체에서 발생하지 않는다는 점도 중요하다고 생각합니다. .. 내부에서 코드 thats 중 하나가 작동하지 않습니다

답변

1

내가 올바르게 이해하면 UIButton을 셀 안에 넣고 UITableView의 RowSelected 이벤트 대신 사용하고 싶습니까?

메모리 문제를 해결하려면 UIButton을 셀에 추가하기 전에 목록에 추가하십시오. 단추의 Tag 속성을 설정하여 단추를 추적 할 수 있습니다. jQuery과가 존재하는 동안 지속됩니다

어딘가 .. 버튼 클릭에 셀을 얻으려면 jQuery과

UIButton b = new UIButton (new RectangleF(140, 10, 385, 40)); 
b.Tag = buttons.Count; 
buttons.Add (b); 
UIButton b2 = new UIButton (new RectangleF(140, 10, 385, 40)); 
b2.Tag = buttons.Count; 
buttons.Add (b2); 

을 생성 함수에서

List<UIButton> buttons = new List<UIButton>(); 

은 같은 것을 할 :

NSIndexPath ns = NSIndexPath.FromRowSection (b.Tag, 0); 
UITableViewCell tcell = tableView.CellAt (ns);