Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How to place an Ad banner with a table view?

$
0
0

I have been trying to get an Ad banner in one of my apps, but there is a lack of information that I can find on how to do this. I have a DialogViewController that I need an Ad banner on. In my actual app it is already contained in a Tab and Navigation controller, so the Nav and Tab bars are present.

I tried playing with some simpler code first to at least get the positioning correct of a UIView (placeholder for an actual Ad) combined with a DialogViewController but I am getting strange results. Attached is a screenshot of the strange results I am seeing where the DialogViewControllers table view is only taking 50% of the screen, and I dont understand why.

Here is the code to produce that screen shot:

    public class FirstController : UIViewController
{
    UIView adView; // The red block
    UIView tableView; // The blue block
    DialogViewController tableController; // Has the Row 1 element in it.

    public FirstController ()
    {
    }

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

        View.BackgroundColor = UIColor.Orange;

        adView = new UIView ();
        adView.BackgroundColor = UIColor.Red;

        tableView = new UIView ();
        tableView.AutosizesSubviews = true;
        tableView.BackgroundColor = UIColor.Blue;

        tableController = new DialogViewController (UITableViewStyle.Grouped, null, true);
        tableController.Root = new RootElement ("Home") {
            new Section() {
                new StringElement("Row 1")
            }
        };
        tableView.AddSubview (tableController.View);

        View.AddSubviews (adView, tableView);
    }

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

        adView.Frame = new RectangleF (0, 0, View.Frame.Width, 44);
        tableView.Frame = new RectangleF (0, 44, View.Frame.Width, View.Frame.Height - 44);
    }
}

Any suggestions on how to get this working? Note, as it stands, the "ad" would cover the nav controller, so I need to figure out how to make that work too.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>