gpt4 book ai didi

c# - 在同一 View Controller 中添加 Collection View 和 TableView - Xamarin iOS

转载 作者:行者123 更新时间:2023-11-29 12:16:32 24 4
gpt4 key购买 nike

我正在创建一个 iPAD 应用程序。我需要在同一个 View Controller 中有一个 UI Collection View 和一个 TableView 。 (屏幕分为 70% - Collection View 和 30% TableView

允许我执行此操作的最佳策略是什么。

PS:我的要求不允许我使用 Split View

公共(public)部分类 POSScreen : UIViewController { UIViewController 主 Controller ;

    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)创建 Controller

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) 在您想要子 Controller 的 Controller 中:

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;

关于c# - 在同一 View Controller 中添加 Collection View 和 TableView - Xamarin iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31849960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com