use*_*056 6 static cells uitableview xamarin.ios
我正在将一个本机Objective-C应用程序移植到Monotouch解决方案中.
我的故事板中有一个tableview,带有一些静态表格单元格.
使用以下目标-c代码a从表中接收选择
- (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;
}
Run Code Online (Sandbox Code Playgroud)
现在我想在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.");
}
}
Run Code Online (Sandbox Code Playgroud)
有人有什么建议吗?
我认为你应该尝试使用WeakDelegate这项工作.
在您的控制器中连接方法如下:
[Export("tableView:didSelectRowAtIndexPath:")]
public void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
//Your code here
}
Run Code Online (Sandbox Code Playgroud)
然后设置 TableView.WeakDelegate = this;
玩弄它,我可能没有完全正确的参数,等等.
| 归档时间: |
|
| 查看次数: |
2376 次 |
| 最近记录: |