如何打开表格行上的视图控制器点击xamarin ios而不使用segue概念?????
答案 0 :(得分:0)
您可以使用present(viewController, animated: true) {}
此方法来展示视图控制器,如果您有导航控制器,则可以使用navigationController?.pushViewController(viewController, animated: true)
答案 1 :(得分:0)
在您的UITableViewSource中,将方法“RowSelected”覆盖为Follows:
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
//Instantialte the Storyboard Object
UIStoryboard storyboard = UIStoryboard.FromName ("YourStoryboardName", null);
//Instantiate the ViewController you want to navigate to.
//Make sure you have set the Storyboard ID for this ViewController in your storyboard file.
//Put this Storyboard ID in place of the TargetViewControllerName in below line.
UIViewController vcInstance = (UIViewController)storyboard.InstantiateViewController ("TargetViewControllerName");
//Get the Instance of the TopViewController (CurrentViewController) or the NavigationViewController to push the TargetViewController onto the stack.
//NavigationController is an Instance of the NavigationViewController
NavigationController.PushViewController(vcInstance, true);
}
或者
使用事件机制,在ViewController中为MyTableSource对象注册此事件,其中添加了TableView。
public class MyTableSource : UITableViewSource
{
public event EventHandler<RowSelectedEventArgs> OnRowSelected;
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
if (OnRowSelected != null) {
OnRowSelected (this, new RowSelectedEventArgs (tableView, indexPath));
}
}
public class MyViewController : UIViewController
{
MyTableSourceObject.OnRowSelected += (s, ev) => {
//Your Navigation Logic Goes Here.
}
}