ViewController not loading from different project
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
- I created an empty Xamarin.iOS (for iPhone/iPad) project (with Visual Studio template) and added Class Library project (for shared logic)
- I’ve added a needed reference.
- Created
TestViewController
inLibrary
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;
}
}
- 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