ViewController Segue Xamarin [英] ViewController Segue Xamarin

查看:25
本文介绍了ViewController Segue Xamarin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现与我在 iOS 中已经完成的功能相同的功能.我首先通过 Ctrl-clickdragviewcontroller 到 viewcontroller 之间创建 segue,然后我使用 segue identifier到达 destinationviewcontroller.

I would like to achieve same functionality that I have already done in iOS. I first create segue between viewcontroller to viewcontroller by Ctrl-click and drag , after that I use segue identifier to reach the destinationviewcontroller.

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

However, in Xamarin if there is no button, you cannot add segue with Ctrl-click and drag. I would like to know is there a way to achieve the same functionality that native iOS provides? I followed the following tutorial but it is based on button segue, not 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);
      }

//在 iOS 代码中

// in iOS code

- (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];

    }
}

推荐答案

你可以通过 Ctrl-Clicking 和 dragging 在两个视图控制器之间添加一个segue源视图控制器底部的区域到第二个视图控制器(见图).转场的属性(例如过渡样式)可以像故事板表面上的任何其他控件一样在属性窗格中进行编辑.

You can add a segue between two view controllers by Ctrl-Clicking and dragging from the grey area at the bottom of the source view controller to the second view controller (see image). The properties for the segue (such as the transition style) can be edited in the properties pane like any other control on the storyboard surface.

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

When you want to use the segue, it is easy enough:

PerformSegue ("detailSegue", this);

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

where detailSegue is the segue identifer as set in the storyboard. Then in PrepareForSegue do your initialisation:

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

        SecondViewController = segue.DestinationViewController;

        // do your initialisation here

    }
}

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

Presumedly, (looking at your sample code), you'd like the initialisation for the destination view controller to be dependent on the row selected in in the table view. For that, you can either add a field to your view controller to hold the selected row, or "abuse" the sender parameter of PerformSegue to pass the NSIndexPath through:

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
}

这篇关于ViewController Segue Xamarin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆