ViewController Segue Xamarin

时间:2015-01-06 18:19:36

标签: ios xamarin

我想实现我在iOS中已经完成的相同功能。我首先在viewcontroller to viewcontrollerCtrl-click之间创建segue,之后我使用drag来到segue identifier

但是,如果没有按钮,则在Xamarin中,您无法使用destinationviewcontrollerCtrl-click添加segue。我想知道有没有办法实现drag提供的相同功能? 我遵循了以下教程,但它基于native iOS,而不是button seguehttp://developer.xamarin.com/guides/ios/user_interface/introduction_to_storyboards/

viewcontroller to viewcontroller segue

Xamarin

//在iOS代码中

 public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
     {
        UIStoryboard board = UIStoryboard.FromName ("MainStoryboard", null);
        SecondViewController sVC = (SecondViewController)board.InstantiateViewController ("SecondViewController");
        ctrl.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
        iv.PresentViewController(sVC,true,null);
      }

1 个答案:

答案 0 :(得分:5)

您可以通过Ctrl-Clickdragging从源视图控制器底部的灰色区域向第二个视图控制器添加两个视图控制器之间的segue(请参见图像)。可以在属性窗格中编辑segue的属性(例如过渡样式),就像在故事板表面上的任何其他控件一样。

当你想使用segue时,它很容易:

PerformSegue ("detailSegue", this);

其中detailSegue是故事板中设置的segue标识符。然后在PrepareForSegue中进行初始化:

public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
    if (segue.Identifier == "detailSegue") {

        SecondViewController = segue.DestinationViewController;

        // do your initialisation here

    }
}

假设(查看示例代码),您希望目标视图控制器的初始化依赖于表视图中选择的行。为此,您可以向视图控制器添加一个字段以保留所选行,或者“#34;滥用"通过以下方式传递NSIndexPath的PerformSegue的sender参数:

public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
    this.PerformSegue ("detailSegue", indexPath); // pass indexPath as sender
} 

然后:

public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
    var indexPath = (NSIndexPath)sender; // this was the selected row

    // rest of PrepareForSegue here
}