你是如何實現自定義UITableViewDelegate的?我建議使用Monotouch的UITableViewSource
,因爲它將UITableViewDataSource
和UITableViewDelegate
組合成一個文件,這使得事情變得更容易。
一些示例代碼:
(在你的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將顯示可用於覆蓋的方法。