I have QLPreviewController
up and running but I'm using PresentModalViewController()
to show the QLPreviewController
directly. For reasons beyond explanation, I would like to have my own UIViewController
which will create its own view and within that view I would like to use the QLPreviewController
. Should be easy I thought, but the code below just does nothing. The QLPreviewControllers ViewDidAppear
never gets called. (In my example below, PreviewController inherits from QLPreviewController
and encapsulates delegate, preview item and source).
Can somebody explain what is wrong with the code below (besides the fact that it is pointless :-))?
Oh, yeah: in my test scenario, I present the controller below modally. It shows up but witout the preview.
public class OuterPreviewController : UIViewController
{
public OuterPreviewController (QLPreviewControllerDataSource oDataSource) : base()
{
this.oDataSource = oDataSource;
}
private PreviewController oPreviewController;
private QLPreviewControllerDataSource oDataSource;
public override void LoadView ()
{
this.View = new UIView();
this.View.Frame = new RectangleF(0, 0, 500, 500);
this.View.BackgroundColor = UIColor.Red;
}
public override void ViewDidAppear (bool animated)
{
// Code execution comes her. No errors, no issues.
base.ViewDidAppear (animated);
this.oPreviewController = new PreviewController();
this.oPreviewController.DataSource = this.oDataSource;
// Preview controller's view is added but it never shows up.
this.View.AddSubview(this.oPreviewController.View);
this.oPreviewController.View.Frame = this.View.Frame;
this.oPreviewController.View.Center = this.View.Center;
}
public override bool ShouldAutorotateToInte开发者_如何学PythonrfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
Found a solution by coincidence today: all ReloadData()
on the preview controller and magically it will show its contents.
This allows to add a QLPreviewController
to an existing view as a subview and embed a preview. It also gets you rid of the toolbar which contains the open in menu.
精彩评论