ViewController Segue Xamarin

2 ios xamarin

我想实现我在iOS中已经完成的相同功能.我首先在viewcontroller to viewcontrollerby Ctrl-click和之间创建segue drag,之后我用它segue identifier来达到destinationviewcontroller.

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

Xamarin

 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);
      }
Run Code Online (Sandbox Code Playgroud)

//在iOS代码中

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"isDetail" sender:self];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([segue.identifier isEqualToString:@"isDetail"]) {

           SecondViewController *fVC = [segue destinationViewController];

    }
}
Run Code Online (Sandbox Code Playgroud)

rda*_*sau 6

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

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

PerformSegue ("detailSegue", this);
Run Code Online (Sandbox Code Playgroud)

detailSegue故事板中设置的segue标识符在哪里.然后PrepareForSegue进行初始化:

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

        SecondViewController = segue.DestinationViewController;

        // do your initialisation here

    }
}
Run Code Online (Sandbox Code Playgroud)

假设(查看示例代码),您希望目标视图控制器的初始化依赖于表视图中选择的行.为此,您可以向视图控制器添加一个字段以保存所选行,或者"滥用" senderPerformSegue 的参数以通过NSIndexPath:

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

然后:

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

    // rest of PrepareForSegue here
}
Run Code Online (Sandbox Code Playgroud)