I am using StoryBoards in Monotouch and have a ViewController which has been designated as the Initial VC. I have a second VC that I want to display programmatically from the ViewDidLoad method of the first VC. The Objective-C steps are like so
Storyboard.InstantiateViewController("SecondVC")
ModalTransitionalStyle
secondVC.delegate = self;
this.PresentViewController(secondVC, true, nil)
How do I accomplish that in MonoTouch C# code?
the VC that I instantiate using Storyboard.Ins..
method does not have a delegate or Delegate property to set. And although my code compiles, I do not see the second view. I see only the first View
Any help highly appreciated
thanks
Ctrl+Drag from the “View Controller” button, to somewhere in the second View Controller(HomeViewController). It can be anywhere in the main box of the second view controller.
You should be able to do this if you call it on a delay. I used a Threading.Timer
to call PresentViewController a second after load. As far as the delegate, a UIViewController does not have that property. You will have to cast to the controller type that is applicable to the controller you are loading. Then you can set the delegate. You will probably want to set the WeakDelegate instead of the Delegate if you want to use this (self).
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Timer tm = new Timer (new TimerCallback ( (state)=> {
this.InvokeOnMainThread (new NSAction (()=> {
UIStoryboard board = UIStoryboard.FromName ("MainStoryboard", null);
UIViewController ctrl = (UIViewController)board.InstantiateViewController ("Number2VC");
ctrl.ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve;
this.PresentViewController (ctrl, true, null);
}));
}), null, 1000, Timeout.Infinite);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With