在 ContainerView 中引用 UIViewController

Posted

技术标签:

【中文标题】在 ContainerView 中引用 UIViewController【英文标题】:Reference UIViewController within ContainerView 【发布时间】:2013-10-31 21:57:50 【问题描述】:

我在 Xamarin 中创建了一个 ContainerView,它自动创建了一个新的 ViewController。

我为此创建了一个名为 Test1ViewController 的类:

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace test1

    public partial class Test2ViewController : UIViewController
    
        public Test2ViewController (IntPtr handle) : base (handle)
        
        

    

我试图在主视图控制器的 ViewDidLoad() 方法中引用这个视图控制器。但是,如果我输入以下内容:

Test2ViewController.PresentViewController(picker, true, null);

我收到一条静态错误消息,这很有意义,因为我试图引用类而不是特定对象。我是否遗漏了什么,如何从父 UIViewController 引用 ContainerView 中的 UIViewController?

我想要实现的是将 Scandit Barcode 扫描仪包含在容器视图中:

        // Setup the barcode scanner
        var picker = new ScanditSDK.SIBarcodePicker ("API-KEY");
        picker.OverlayController.Delegate = new BarcodeScanner ();

        Test2ViewController.PresentViewController(picker, true, null);
        picker.StartScanning ();

【问题讨论】:

【参考方案1】:

假设变量 picker 应该代表一个 Test2ViewController 实例:

public override void ViewDidLoad()

  base.ViewDidLoad();

  this.picker = new Test2ViewController(); 
  this.PresentViewController(picker, true, null);  

【讨论】:

抱歉,我已经对我的问题进一步说明了选择器是什么。 @Joseph ContainerView 是什么意思? 我的理解是我添加了一个容器视图(图表的蓝色部分),它自动生成了 Test2ViewController。我想要的是条形码扫描仪(选择器)填充图表上的蓝色区域。 @Joseph BarcodeScanner 是从 UIView 还是从 UIViewController 派生的? picker.view 派生自 UIView

以上是关于在 ContainerView 中引用 UIViewController的主要内容,如果未能解决你的问题,请参考以下文章