首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ViewController Segue Xamarin

ViewController Segue Xamarin
EN

Stack Overflow用户
提问于 2015-01-06 18:19:35
回答 1查看 6.6K关注 0票数 2

我希望实现我在iOS中已经做过的相同的功能。我首先通过Ctrl-clickdragCtrl-clickdrag之间创建segue,然后使用segue identifier到达destinationviewcontroller

但是,在Xamarin中,如果没有按钮,则不能使用Ctrl-clickdrag添加segue。我想知道是否有一种方法可以实现与native iOS相同的功能?我遵循了下面的教程,但它是基于button segue,而不是viewcontroller to viewcontroller seguestoryboards/

Xamarin

代码语言:javascript
复制
 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代码中

代码语言:javascript
复制
- (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];

    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-07 00:51:32

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

当您想要使用segue时,它非常容易:

代码语言:javascript
复制
PerformSegue ("detailSegue", this);

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

代码语言:javascript
复制
public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
    if (segue.Identifier == "detailSegue") {

        SecondViewController = segue.DestinationViewController;

        // do your initialisation here

    }
}

首先(查看示例代码),您希望目标视图控制器的初始化取决于表视图中选择的行。为此,可以向视图控制器中添加字段以保存选定的行,或者“滥用”PerformSegue的PerformSegue参数以传递NSIndexPath:

代码语言:javascript
复制
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
    this.PerformSegue ("detailSegue", indexPath); // pass indexPath as sender
} 

然后:

代码语言:javascript
复制
public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
    var indexPath = (NSIndexPath)sender; // this was the selected row

    // rest of PrepareForSegue here
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27804690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档