Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Call Instantiate UIViewController from UITableViewController in Visual Studio using C# and Xamarin

So using Visual Studio, C# and Xamarin and I have this I have a UITableViewController which lists a selection of records and when the user clicks on one of these I want them to see a UIViewController page with the full record details displayed.

When a record is select this function is correctly invoked in RowSelected, the full code is below.

However I am seeing 2 errors:
PartsViewController PartsView= this.storyboard.InstantiateViewController("PartsViewController") as PartsViewController;

Shows this error for storyboard:

this.PresentViewController(PartsView, true, null);

Shows this error for PresentViewController

This is my first IOS App so can anyone show me the error of my ways please.
Code:

public partial class PartsListController : UITableViewController
{
    public List<String> Partss { get; set; }
    public List<String> Ndx { get; set; }
    static readonly NSString PartsListCellId = new NSString("PartsListCell");

    public PartsListController (IntPtr handle) : base (handle)
    {
        TableView.RegisterClassForCellReuse(typeof(UITableViewCell), PartsListCellId);
        TableView.Source = new PartsDataSource(this);
        Partss = new List<string>();
        Ndx = new List<String>();
    }

    class PartsDataSource : UITableViewSource
    {
        PartsListController controller;

        public PartsDataSource(PartsListController controller)
        {
            this.controller = controller;
        }

        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            PartsViewController PartsView= this.storyboard.InstantiateViewController("PartsViewController") as PartsViewController;
            string selection = controller.Partss[indexPath.Row];
            string pos = controller.Ndx[indexPath.Row];
            this.PresentViewController(PartsView, true, null);
        }

        public override nint RowsInSection(UITableView tableView, nint section)
        {
            return controller.Partss.Count;
        }

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.DequeueReusableCell(PartsListController.PartsListCellId);

            var row = indexPath.Row;
            cell.TextLabel.Text = controller.Partss[row];
            return cell;
        }
    }
}

Tagged:

Best Answer

  • kevsboxkevsbox GBMember
    Accepted Answer

    Sorted it with this

    public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                PartsViewController PartsView= controller.storyboard.InstantiateViewController("PartsViewController") as PartsViewController;
                string selection = controller.Partss[indexPath.Row];
                string pos = controller.Ndx[indexPath.Row];
                controller.NavigationController.PushViewController(RecipeView, true);
            }
    
    

Answers

  • kevsboxkevsbox GBMember
    Accepted Answer

    Sorted it with this

    public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                PartsViewController PartsView= controller.storyboard.InstantiateViewController("PartsViewController") as PartsViewController;
                string selection = controller.Partss[indexPath.Row];
                string pos = controller.Ndx[indexPath.Row];
                controller.NavigationController.PushViewController(RecipeView, true);
            }
    
    
  • ColeXColeX Member, Xamarin Team Xamurai

    Please accept the answer if If problem has been solved .


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Sign In or Register to comment.