2016-11-17 2 views
0

내 TableView 용 맞춤 TableCell을 만들었습니다. 사용자 정의 셀에는 Button이 있습니다. 그래서 Button이 click.and 일 때 새로운 ViewController를 열고 싶습니다. 그래서 새로운 ViewController를 열기 위해 Custom TableCell에서 이벤트를 만드는 법.맞춤 TableCell 버튼 iOS의 새 ViewController (Xamarin)

나는 이런 식으로 만들고있다.이 올바른 방법인가요?

내 CustomCell :

public partial class CaseHistotyTableCell : UITableViewCell 
    { 
     public static readonly NSString Key = new NSString("CaseHistotyTableCell"); 
     public static readonly UINib Nib; 

     static CaseHistotyTableCell() 
     { 
      Nib = UINib.FromName("CaseHistotyTableCell", NSBundle.MainBundle); 
     } 

     protected CaseHistotyTableCell(IntPtr handle) : base(handle) 
     { 
      // Note: this .ctor should not contain any initialization logic. 
     } 

     public static CaseHistotyTableCell Create() 
     { 
      return (CaseHistotyTableCell)Nib.Instantiate(null, null)[0]; 
     } 
     internal void BindData(string hospitalLabel, string addressLabel, string drLabel, string patientLabel) 
     { 
      this.lbl_hospitalName.Text = hospitalLabel; 
      this.lbl_address.Text = addressLabel; 
      this.lbl_drName.Text = drLabel; 
      this.lbl_patientName.Text = patientLabel; 

      this.lbl_address.TextColor = UIColor.Clear.FromHexString("#000000", 0.54f); 
      this.lbl_patientName.TextColor = UIColor.Clear.FromHexString("#000000", 0.54f); 
      this.lbl_hospitalName.TextColor = UIColor.Clear.FromHexString("#000000", 0.87f); 
      this.lbl_drName.TextColor = UIColor.Clear.FromHexString("#000000", 0.87f); 
      this.btn_createAppointment.SetTitleColor(UIColor.Clear.FromHexString("#0072BA",1.0f), UIControlState.Normal); 
      this.btn_viewDetail.SetTitleColor(UIColor.Clear.FromHexString("#0072BA", 1.0f), UIControlState.Normal); 

      this.btn_viewDetail.TouchUpInside += (sender, e) => 
      { 

      }; 


     } 



     public override CGRect Frame 
     { 
      get 
      { 
       return base.Frame; 
      } 

      set 
      { 
       value.Y += 4; 
       value.Height -= 2 * 4; 
       base.Frame = value; 
      } 
     } 
    } 

sourceClass를 :

public class CaseHistorySourceClass : UITableViewSource 
    { 
     private List<CaseSearchItem> caseSearchItems; 
     public CaseSearchItem caseSearchItem; 

    public CaseHistorySourceClass(List<CaseSearchItem> caseSearchItems) 
    { 
     this.caseSearchItems = caseSearchItems; 
    } 
    public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
    { 
     CaseHistoryTableCell cell = tableView.DequeueReusableCell(CaseHistoryTableCell.Key) as CaseHistoryTableCell ?? CaseHistoryTableCell.Create(); 
     var item = caseSearchItems[indexPath.Row]; 

     cell.BindData(item.Organization, item.Address, item.Doctor, item.UserName); 

     cell.Layer.MasksToBounds = false; 
     cell.Layer.CornerRadius = 10.0f; 
     cell.BackgroundColor = UIColor.White; 



     return cell; 
    } 

    public override nint RowsInSection(UITableView tableview, nint section) 
    { 
     return caseSearchItems.Count; 
    } 


} 

내가 iOS 및 자 마린 새로운 오전. 어떤 도움을 주셔서 감사합니다.

+0

사용자 정의 셀에 대해 u는 'TableCell' 권한을 렌더링하고 있습니다. 클릭 할 때 ur 테이블 셀에서'button clicked '메소드를 호출해야한다고 가정합니다. 중단 점을 두어 클릭하면보기를 호출해야합니다. that thats extends TabbleCell – Smit

답변

0

이 시도 :

당신이 당신의 tableview에 대한 데이터 소스를 정의보기 컨트롤러, 예를 들어 뷰 컨트롤러에 대한 변수를 추가에서
this.btn_viewDetail.TouchUpInside += (sender, e) => 
    { 
    TargetController myTarget = new TargetController(); 
    myTarget.YourString = "Your value here"; 
    this.NavigationController.PushViewController(myTarget, true); 
    }; 
+0

'ButtonClick'을 클릭하고 'RowClick'을 클릭합니다. – Ironman

0

..

public class mytableDataSource : UITableViewSource 
    { 
     private ViewController owner; 
     List<string> tableItems; 
     public mytableDataSource(ViewController cntrlr, List<string items) 
     { 
      tableItems = items; 
      owner = cntrlr; 

     } 

     public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
     { 
      var cell = tableView.DequeueReusableCell("your identifier"); 
      //cell. BindData(..... 
      cell.getDetailButton.Tag = indexPath.Row; 
      cell.getDetailButton.TouchUpInside -= handler; 
      cell.getDetailButton.TouchUpInside += handler; 

     } 
     void handler(Object sender, EventArgs args) 
     { 
      nint tag = btn.Tag; 
      TargetController myTarget = new TargetController(); 
      myTarget.YourString = list[]; 
      owner.NavigationController.PushViewController(myTarget, true); 
     } 

    } 

당신의 tableview에 데이터 소스를 할당

tbl.Source = new mytableDataSource(lstService, this); 
    tbl.ReloadData(); 
예를 들어 을 전달하십시오.

뷰 컨트롤러에서 셀 버튼을 사용할 수있게하려면 cs 파일에 속성을 만듭니다.

public UIButton getDetailButton 
    { 
    get 
     { 
      return btn_viewDetail; 
     } 
    } 
+0

나는 이것을 시험해보고 나중에 이야기한다. – Ironman

+0

@ 아이언 (Ironman) 여러 번 호출 된 셀을 가져올 때 버튼에 여러 대리자 지정이 지정되지 않도록 처리기를 사용하여 업데이트 답변을 얻습니다. – Darshana

+0

'GetCell' 메소드에서'this.btn_viewDetail.Tag = indexPath.Row;'에 접근 할 수 없습니까? – Ironman