【问题标题】:Adding a Collection View and a Table View in the same view controller - Xamarin iOS在同一视图控制器中添加集合视图和表视图 - Xamarin iOS
【发布时间】:2015-08-06 07:56:08
【问题描述】:

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

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

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

公共部分类POSScreen:UIViewController { UIViewController 主控制器;

    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);
        }



    }
}

谢谢

【问题讨论】:

  • 您的要求是否明确指出“不要使用 UISplitViewController”或者您对 UISplitViewController 有一些问题?
  • 嗨,我需要在我的应用程序中有一个导航控制器,因为在 UI 拆分视图中需要是应用程序的根视图控制器,因此不能有拆分视图。是的,我知道 master 和 detail 可以有他们的导航栏项目。我确实实现了 UI 拆分视图,但我走到了死胡同。
  • 老实说,我不明白有什么问题。如果你需要把 UICollectionView 和 UITableView 放在一起,就去做,计算它们的帧数。就这样。框架指定视图边框的 X/Y,您可以将这两个视图紧挨着放置。
  • 是的,我得出了同样的结论 - 查看更新的代码我是新的 ios 开发,仅此而已
  • 你需要添加更多的 ViewController 到你的 viewController 吗?如果不是,那么只需添加 Views(UITableView, UICollectionView) 而不是 ViewControllers(UITableViewController, UICollectionViewController)。

标签: c# ios xamarin tableview collectionview


【解决方案1】:

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多