繁体   English   中英

在同一视图控制器中添加集合视图和表视图-Xamarin iOS

[英]Adding a Collection View and a Table View in the same view controller - Xamarin iOS

我正在创建一个iPAD应用程序。 我需要在同一视图控制器中有一个UI集合视图和一个表视图。 (屏幕分为70%-集合视图和30%表格视图

让我这样做的最佳策略是什么?

PS:我的要求不允许我使用拆分视图

公共局部类POSScreen:UIViewController {UIViewController MainController;

    UIViewController SecondaryController;

    UIView MainView;
    UIView SecondaryView;

    /* The Widths */
    nfloat leftSide;
    nfloat rightSide;

    public POSScreen () : base ("POSScreen", null)
    {



    }

    public override void DidReceiveMemoryWarning ()
    {
        // Releases the view if it doesn't have a superview.
        base.DidReceiveMemoryWarning ();

        // Release any cached data, images, etc that aren't in use.
    }

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

        try {
            // Perform any additional setup after loading the view, typically from a nib.
            leftSide = ((nfloat.Parse("65") / nfloat.Parse("100")) * nfloat.Parse( View.Frame.Width.ToString()));
            rightSide = ((nfloat.Parse("35") / nfloat.Parse("100")) * View.Frame.Width);

            MainController = new CategoriesProductsSimpleCollectionViewController();
            SecondaryController = new RightSideItemDetail ();

            (MainController as IViewController).SetCollectionViewFrame (new CoreGraphics.CGRect (0, 40, leftSide, View.Frame.Height));
            (SecondaryController as IViewController).SetCollectionViewFrame (new CoreGraphics.CGRect (View.Frame.Width, 40, rightSide, View.Frame.Height));


            this.Add (this.MainController.View);
            this.Add (this.SecondaryController.View);
        } catch (Exception ex) {
            Console.WriteLine (ex.Message);
        }



    }
}

谢谢

1)创建控制器

public SomeViewController(UIColor color, CGRect frame) : base("SomeViewController", null)
{
     this.color = color;
     this.frame = frame;
}

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

     this.View.BackgroundColor = color;
     this.View.Frame = frame;
}

2)在您想要子控制器的控制器中:

var MainController = new SomeViewController(UIColor.Black, new CGRect(0, 0, 100, 500));
var SecondaryController = new SomeViewController(UIColor.Green, new CGRect(150, 0, 100, 500));

this.AddChildViewController(MainController);
this.AddChildViewController(SecondaryController);
this.Add(this.MainController.View);
this.Add(this.SecondaryController.View);

我创建的CGRect只是示例。 您可以使用UIScreen.MainScreen.Bounds;计算正确的值UIScreen.MainScreen.Bounds;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM