2011-04-05 7 views
0

커스텀 UITableViewDelegate를 사용하고 있고, 내 컨트롤러에서 tableview에 rowselected가있을 때 일부 코드를 실행하려고합니다. UITableViewDelegate 이미 RowSelected라는 이벤트가 있지만 그것을 동일한 이름을 가진 UITableViewDelegate 메서드가 있기 때문에 추측하고 그것을 사용할 수 없습니다 것으로 나타났습니다.monotouch UITableViewDelegate RowSelected 이벤트를 사용할 수 없습니까?

내가 작성하는 경우 :

mytableviewdelegate.RowSelected + =이 MyEventAPIHandler을;

이 컴파일되지 않고 오류가 있습니다 :

모든 아이디어, 내가 그렇게 임 잘되는 주위에 일이 "그것은 '방법 그룹'때문에 'RowSelected'에 할당 할 수 없습니다" 이것이 MonoTouch의 버그인지 실제로 조사하고 있습니까?

답변

2

커스텀 UITableViewDelegate를 어떻게 구현하고 있습니까? 나는 Monotouch의 UITableViewSource을 사용하여 UITableViewDataSourceUITableViewDelegate을 하나의 파일에 결합하여 훨씬 쉽게 작업을 수행 할 것을 제안합니다.

일부 예제 코드 :

(당신의 UIViewController에서 UITableView 포함)이을위한 새로운 클래스를 생성 할 수 있습니다 그리고

tableView.Source = new CustomTableSource(); 

을 : 그것은해야

public class CustomTableSource : UITableViewSource 
{ 
    public CustomTableSource() 
    { 
     // constructor 
    } 
    // Before you were assigning methods to the delegate/datasource using += but 
    // in here you'll want to do the following: 
    public override int RowsInSection (UITableView tableView, int section) 
    { 
     // you'll want to return the amount of rows you're expecting 
     return rowsInt; 
    } 

    // you will also need to override the GetCells method as a minimum. 
    // override any other methods you've used in the Delegate/Datasource 
    // the one you're looking for in particular is as follows: 

    public override void RowSelected (UITableView tableView, NSIndexPath indexPath) 
    { 
     // do what you need to here when a row is selected! 
    } 
} 

을 시작하는 데 도움이됩니다. UITableViewSource 클래스에서는 항상 public override을 입력 할 수 있으며 MonoDevelop는 어떤 메소드를 재정의 할 수 있는지 보여줍니다.

관련 문제