我將本機Objective-C應用程序移植到Monotouch解決方案。MonoTouch如何爲具有靜態單元的UITableViewController實現RowSelected
我在故事板中有一個tableview,有一些靜態表格單元格。
使用以下Objective-C代碼一個接一個選擇從表
- (void) tableView:(UITableView *) aTableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath
{ // remove the row highlight
[aTableView deselectRowAtIndexPath:indexPath animated:YES];
switch(indexPath.row) {
case 0: [self callWebsite]; break;
case 1: [self sendEmail]; break;
case 2: [self makePhoneCall]; break;
}
return;
}
現在我想要做的MonoTouch是相同的,但不能找出我如何和所有的例子在網絡上找到,正在使用DataSource和UITableViewDelegate。
但是,當使用這種方法時,我的「靜態」單元被刪除,替換。
這就是我想要
public partial class ContactViewController : UITableViewController
{
public ContactViewController (IntPtr handle) : base (handle)
{
this.TableView.Delegate = new CustomTableViewDelegate();
}
}
public class CustomTableViewDelegate : UITableViewDelegate
{
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
// Remove the row highlight
RowDeselected(tableView, indexPath);
/*
// Is this section our "button" section?
switch(indexPath.row) {
case 0: [self callWebsite]; break;
case 1: [self sendEmail]; break;
case 2: [self makePhoneCall]; break;
}
*/
Console.WriteLine("Do something meaningfull.");
}
}
有人什麼建議嗎?
我不緊隨其後,你的細胞如何去除? 您粘貼的代碼是用於選中單元格時的操作,並且您有一些註釋代碼,爲什麼要註釋掉它? – 2012-04-23 21:10:25
註釋掉的代碼是我的objective-c代碼的複製粘貼,因爲我正在將它轉換爲C#。對這個問題沒有任何重要性。我不知道爲什麼細胞被移除。我認爲這是因爲我沒有實現從代碼創建表時使用的方法'numberOfRowsInSection'和'cellForRowAtIndexPath'。不是靜態的......「我想......」 – user1346056 2012-04-24 12:24:32