How to take row selected from tableview and navigate to new view

I have my row selected working, I can get the associated values but cannot for the life of me navigate to a new controller to do something with the data. Here is my code with many commented out trials (all errors):

       int t = indexPath.Row; 
        string key = shippers[indexPath.Row].key;
        UIStoryboard board = UIStoryboard.FromName("Main", null);
        UIViewController controller = board.InstantiateViewController("ShipperDetailViewController") as UIViewController;
        int ix = 0;


        ShipperDetailViewController ctrl2 = board.InstantiateViewController("ShipperDetailViewController") as ShipperDetailViewController;

Now how do I navigate to ctrl2 or is there a better way. Also - I need to pass the "key" value to the new view. This is not a tableviewcontroller but a tableview control.

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    There are many ways to navigate to the new page. Are you using a UINavigationController? If so, you can use

    this.NavigationController.PushViewController(ctrl2, true);
    

    If not, you can present the view controller:

    this.PresentViewController(ctrl2, true, completionHandler)  // completionHandler can be null
    

    As for passing in your data, presumably ShipperDetailViewController should have a property that you can assign an object that contains your data to, and if so just assign the object(s) that have your data to the appropriate property(ies) in ShipperDetailViewController right before pushing it or presenting it. .

Sign In or Register to comment.