从TableView中选择的行作为新TableView上的标题

时间:2017-12-13 15:06:50

标签: xamarin xamarin.ios navigation tableview segue

我的TableView中有数据。我使用滑动操作。当我从左向右滑动时,我可以选择按“Bearbeiten”。点击“Bearbeiten”即可打开新的TableView

此新TableView的导航控制器的标题应与刷过的单元格具有相同的名称。

我试过这种方式:

1.创建一个列表    2.将数据添加到此列表中    3.准备Segue    4.将列表的第一个条目推送到新ViewController    5.添加带有数据的Navigation.title

但它不起作用。我做错了什么?

mycode的:

首先TableView

....

List<string> wordnewvc = new List<string>();

....

    public UIContextualAction ContextualDefinitionAction(int row)
    {
        var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal, "Bearbeiten", (ReadLaterAction, view, success) => {

                                                                wordnewvc.Add(words[row]);

                                                                secondViewController controller = this.Storyboard.InstantiateViewController("secondViewController") as secondViewController;
                                                                this.NavigationController.PushViewController(controller, true);

                                                            });
        action.BackgroundColor = UIColor.Orange;
        return action;
    }


    public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
    {
        base.PrepareForSegue(segue, sender);

        var secondViewController = segue.DestinationViewController as secondViewController;

        secondViewController.firma = wordsnewvc[0];
    }

第二个ViewController

        public string firma
    {
        get;
        set;
    }

    public secondViewController (IntPtr handle) : base (handle)
    {
    }


    public override void ViewDidLoad()
    {
        base.ViewDidLoad();


        NavigationItem.Title = firma;
    }

1 个答案:

答案 0 :(得分:0)

您混合了Navigation PushSegue

解决方案1:导航推送

不需要方法PrepareForSegue

var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal, "Bearbeiten", (ReadLaterAction, view, success) => {
    secondViewController controller = this.Storyboard.InstantiateViewController("secondViewController") as secondViewController;
    controller.firma = wordsnewvc[0];
    this.NavigationController.PushViewController(controller, true);
});

溶液2:Segue公司

var action = UIContextualAction.FromContextualActionStyle(UIContextualActionStyle.Normal, "Bearbeiten", (ReadLaterAction, view, success) => {
    this.PerformSegue(identifierInStoryboard, null);
});

public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender)
{
     if(segue.Identifier == identifierInStoryboard)
     {
         var secondViewController = segue.DestinationViewController as secondViewController;
         secondViewController.firma = wordsnewvc[0];
     }  
}