ViewController not loading from different project

Published

In my solution, I have one iOS project that supports both iPads and iPhones. I would like to split it to have

  • iOS shared project (shared views and services for both iPads and iPhones)
  • iPad project with reference to the shared one
  • iPhone project with reference to the shared one

I had troubles doing that, so

  1. I created an empty Xamarin.iOS (for iPhone/iPad) project (with Visual Studio template) and added Class Library project (for shared logic)
  2. I’ve added a needed reference.
  3. Created TestViewController in Library project (simple one with a label only). No storyboard behind it. Just
public class TestViewController : UIViewController
{
    public TestViewController()
    {
    }

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

        this.View.BackgroundColor = UIColor.Cyan;

        var label = new UILabel
        {
            TranslatesAutoresizingMaskIntoConstraints = true,
            Text = "Love Santa Claus"
        };
        View.Add(label);

        label.CenterXAnchor.ConstraintEqualTo(View.CenterXAnchor).Active = true;
        label.CenterYAnchor.ConstraintEqualTo(View.CenterYAnchor).Active = true;
    }
}
  1. Navigate to that ViewController in AppDelegate

the problem is that the app gets stuck on the LaunchScreen. I put break point in line
mainNavController.PushViewController(new TestViewController(), true);
and it gets hit but neither constructor nor ViewDidLoad is getting called in TestViewController.

I’m looking for ideas about what did I miss.

Source: Xamarin.ios Questions

Published
Categorized as Uncategorised Tagged ,

Answers

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq