简体   繁体   English

同一视图控制器中的TableView和Collection视图布局

[英]TableView and Collection view Layout in same view controller

I have two UIViewControllers , When I click on a button of first UIViewController then tableView(Of Second UIViewController) should open, and when I click on another button of First UIViewController then Collection view(Of Second UIViewController) should open. 我有两个UIViewControllers ,当我单击第一个UIViewController的按钮时,应该打开tableView(第二UIViewController的),而当我单击第一个UIViewController另一个按钮时,则应该打开Collection视图(第二个UIViewController)。

I mean When Table View will open Collection view will be hidden and Vice versa, both I want in a single View controller. 我的意思是,当“表视图”将打开时,“收藏夹”视图将被隐藏,反之亦然,我都希望在单个视图控制器中。
In image you can see that TableView open with images, but when I will click on first cell the collection view should open in same layout.I mean it has to show like this. 在图像中,您可以看到TableView随图像一起打开,但是当我单击第一个单元格时,集合视图应该以相同的布局打开。我的意思是它必须像这样显示。

I am new in UI. 我是UI新手。 So How can I implement the UI. 那么我该如何实现UI。

Thanks. 谢谢。

在此处输入图片说明

Thanks for asking question. 感谢您提出问题。

I am assuming you are doing in this way: 我假设您是以这种方式做的:

First put a global Bool Variable called: flagIsShowTableView 首先放一个全局的布尔变量,叫做:flagIsShowTableView

Now on your FirstViewController when you click on buttonTable for table: 现在,当您单击表的buttonTable时,在FirstViewController上:

you have to set Bool: flagIsShowTableView = true 您必须设置Bool: flagIsShowTableView = true

Now when you click on buttonCollection: 现在,当您单击buttonCollection时:

you have to set Bool: flagIsShowTableView = false 您必须设置布尔: flagIsShowTableView = false

Now on SecondViewController: 现在在SecondViewController上:

in ViewWillAppear: you have to manage in this way: 在ViewWillAppear中:您必须通过以下方式进行管理:

if(flagIsShowTableView) {
  tblView.hidden = false
  colView.hidden = true
} else {
  colView.hidden = false
  tblView.hidden = true
}

I am sure that you have set and manage all the delegate and datasources methods. 我确定您已经设置和管理所有委托和数据源方法。

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

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