Quantcast
Channel: OxyPlot (moved to GitHub)
Viewing all articles
Browse latest Browse all 2061

New Post: iOS - Can't Add PlotView via AddSubview

$
0
0
I think I found the answer...I do not believe this is a bug, but feedback is welcome.

Take the code in the ExampleBrowser for iOS
private void GraphView(ExampleInfo exampleInfo)
{
    var dvc = new GraphViewController (exampleInfo);
    navigation.PushViewController (dvc, true);
}
What I was attempting to do in my app was to take a UIViewController and add it to a second UIViewController, an allowed operation I believe, by doing the following
private void GraphView(ExampleInfo exampleInfo)
{
    var dvc = new GraphViewController (exampleInfo);
    var newGraphViewController = new UIViewController ();   
    newGraphViewController.AddChildViewController (dvc);
    newGraphViewController.View.AddSubview (dvc.View);
    navigation.PushViewController (newGraphViewController, true);
}
The above produced an empty view, nothing to show on the screen. The reason is, when dvc calls LoadView() the View.Frame of dvc is 0,0,0,0, the frame has no position and no size.

To properly get this to work one needs to manually set the View.Frame of the child UIViewController. The following code works fine:
private void GraphView(ExampleInfo exampleInfo)
{
    var dvc = new GraphViewController (exampleInfo);
    var newGraphViewController = new UIViewController ();
    dvc.View.Frame = newGraphViewController.View.Frame;
    newGraphViewController.AddChildViewController (dvc);
    newGraphViewController.View.AddSubview (dvc.View);
    navigation.PushViewController (newGraphViewController, true);
}
Not a bug, I believe this is as designed by iOS.

Viewing all articles
Browse latest Browse all 2061

Latest Images

Trending Articles



Latest Images

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