ili*_*ght 3 uinavigationcontroller xamarin.ios mkmapview ios xamarin
我在主屏幕上有一个TableView,它位于导航控制器内.现在,当选择一行时,我想显示一个MapView.
我想访问导航控制器并将MapViewController推入其中.我怎样才能实现这一目标?
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
}
Run Code Online (Sandbox Code Playgroud)
我假设你的RowSelected方法在你的UITableViewController,对吗?在这种情况下,它很容易,因为您可以访问自动设置为父级的NavigationController属性(定义UIViewcontroller)UINavigationController
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
var index = indexPath.Row;
NavigationController.PushViewController (new MyDetailViewController(index));
}
Run Code Online (Sandbox Code Playgroud)
现在,您可能应该使用a UITableViewSource,并覆盖RowSelected那里.在这种情况下,请确保UINavigationController通过构造函数注入可用:
tableViewController = new UITableViewController();
tableViewController.TableView.Source = new MyTableViewSource (this);
class MyTableViewSource : UITableViewSource
{
UIViewController parentController;
public MyTableViewSource (UIViewController parentController)
{
this.parentController = parentController;
}
public override int RowsInSection (UITableView tableview, int section)
{
//...
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
//...
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
var index = indexPath.Row;
parentController.NavigationController.PushViewController (new MyDetailViewController(index));
}
}
Run Code Online (Sandbox Code Playgroud)
替换你MyDetailViewController的这个通用答案MapViewController,你应该全部设置.
| 归档时间: |
|
| 查看次数: |
12644 次 |
| 最近记录: |