How to use QLPreviewController in non-modal mode? Why is my code not working?

I have QLPreviewController, but I use PresentModalViewController()to show QLPreviewControllerdirectly. For reasons not related to the explanation, I would like to have my own UIViewController, which will create my own view, and in this view I would like to use QLPreviewController. It should be easy, I thought, but the code below just doesn't do anything. QLPreviewControllers is ViewDidAppearnever called. (In my example below, the PreviewController inherits from QLPreviewControllerand encapsulates the delegate, preview element, and source). Can someone explain what is wrong with the code below (except that it is pointless :-))? Oh yes: in my test case, I present the controller below modally. It is displayed, but without 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 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 ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
            {
                return true;
            }
        }
+3
source share
1

: ReloadData() .

QLPreviewController subview . , .

+3

Source: https://habr.com/ru/post/1793312/


All Articles