I am programming an Application on Xamarin.IOS. I have a Tabbed Layout as for my Main View and all the UIElements are set in the Storyboard. Now, what i need to do, because i want to implement IAds, i want my Application to be a Split view, with the IAd View Controller as the Detail View, and my usual TabbedLayout as the main view.
So, yeah, my precise question would be:
As all my Layout is loaded from the Storyboard: How can i pass an instance of the View that gets loaded usually to my SplitViewController?
Any tips you can give, are helpful, i really need this for my work!!
To provide some Code:
I am trying to load my initial View (Which is the TabBarController) like this in the AppDelegate.cs:
SplitViewContoller splitView = new SplitViewContoller();
IADViewController iAdVC = new IADViewController (splitView);
Console.WriteLine ("Root" + Window.RootViewController);
Window.RootViewController = iAdVC;
That is working fine, except that the view that usually appears doesn't get loaded... The IAD shows up but the rest of the screen is an empty TabBarController.
Here is my SplitViewController:
public class SplitViewContoller : UISplitViewController
{
UIViewController masterView, detailView;
public SplitViewContoller () : base()
{
// create our master and detail views
masterView = new TabBarController();
detailView = new IADViewController (new TabBarController());
// create an array of controllers from them and then
// assign it to the controllers property
ViewControllers = new UIViewController[]
{ masterView, detailView }; // order is important
}
public override bool ShouldAutorotateToInterfaceOrientation
(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
The View that i want to be at the bottom of my screen: (See Monotouch.Dialog and iAds for details)
public partial class IADViewController : UIViewController
{
private UIViewController _anyVC;
private MonoTouch.iAd.ADBannerView _ad;
public IADViewController (UIViewController anyVC)
{
_anyVC = anyVC;
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
View.AddSubview (_anyVC.View);
Version version = new Version (MonoTouch.Constants.Version);
if (version > new Version (6,0))
{
try {
_ad = new MonoTouch.iAd.ADBannerView (MonoTouch.iAd.ADAdType.Banner);
_ad.Hidden = true;
_ad.FailedToReceiveAd += HandleFailedToReceiveAd;
_ad.AdLoaded += HandleAdLoaded;
View.BackgroundColor = UIColor.Clear;
_anyVC.View.Frame = View.Bounds;
View.AddSubview (_ad);
} catch {
}
} else {
Resize ();
}
}
public override void DidRotate (UIInterfaceOrientation fromInterfaceOrientation)
{
base.DidRotate (fromInterfaceOrientation);
Resize ();
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
Resize ();
}
void Resize ()
{
UIView.Animate (.25,
() => {
if (_ad !=null && _ad.Hidden == false) {
_anyVC.View.Frame = new RectangleF (0, 0, this.View.Bounds.Width, this.View.Bounds.Height - _ad.Frame.Height);
} else {
_anyVC.View.Frame = View.Bounds;
}
});
if(_ad!=null)
_ad.Frame = new RectangleF (0, _anyVC.View.Bounds.Height, this.View.Bounds.Width, _ad.Frame.Height);
}
void HandleAdLoaded (object sender, EventArgs e)
{
if (_ad == null)
return;
_ad.Hidden = false;
Resize ();
}
void HandleFailedToReceiveAd (object sender, AdErrorEventArgs e)
{
if (_ad == null)
return;
_ad.Hidden = true;
Resize ();
}
}