我希望实现我在iOS中已经做过的相同的功能。我首先通过Ctrl-click和drag在Ctrl-click和drag之间创建segue,然后使用segue identifier到达destinationviewcontroller。
但是,在Xamarin中,如果没有按钮,则不能使用Ctrl-click和drag添加segue。我想知道是否有一种方法可以实现与native iOS相同的功能?我遵循了下面的教程,但它是基于button segue,而不是viewcontroller to viewcontroller segue。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代码中
- (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];
}
}发布于 2015-01-07 00:51:32
您可以通过Ctrl-Clicking和dragging将两个视图控制器从源视图控制器底部的灰色区域添加到第二个视图控制器(参见图像)之间。可以像故事板表面上的任何其他控件一样,在属性窗格中编辑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
}
}首先(查看示例代码),您希望目标视图控制器的初始化取决于表视图中选择的行。为此,可以向视图控制器中添加字段以保存选定的行,或者“滥用”PerformSegue的PerformSegue参数以传递NSIndexPath:
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
}https://stackoverflow.com/questions/27804690
复制相似问题