IOS Swift-如何在具有不同数据的collectionview中使用2个表视图
我正在开发一个应用程序,其中我有一个collectionview和两个不同的TableView。但我需要知道的是如何识别此时哪个tableview中充满了数据。您需要为他们提供不同的标记,然后围绕这些标记的使用构建您的方法。您需要为他们提供不同的标记,然后围绕这些标记的使用构建您的方法。您需要为他们提供不同的标记和然后围绕这些标记的使用构建方法。您需要为它们指定不同的标记,然后围绕这些标记的使用构建方法。每个IOS Swift-如何在具有不同数据的collectionview中使用2个表视图,ios,swift,Ios,Swift,我正在开发一个应用程序,其中我有一个collectionview和两个不同的TableView。但我需要知道的是如何识别此时哪个tableview中充满了数据。您需要为他们提供不同的标记,然后围绕这些标记的使用构建您的方法。您需要为他们提供不同的标记,然后围绕这些标记的使用构建您的方法。您需要为他们提供不同的标记和然后围绕这些标记的使用构建方法。您需要为它们指定不同的标记,然后围绕这些标记的使用构建方法。每个UIView对象都有一个标记属性,即 您可以这样设置: myTableView1.tag
UIView
对象都有一个标记
属性,即
您可以这样设置:
myTableView1.tag = Int.min
myTableView2.tag = Int.max
在委托
和数据源
方法中:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let rowCount: Int
if tableView.tag == Int.Min
{
rowCount = self.dataForTableView1.count
} else
{
rowCount = self.dataForTableView2.count
}
return rowCount
}
使用
标记
值来标识右侧的表视图
。每个UIView
对象都有一个标记
属性,即
您可以这样设置:
myTableView1.tag = Int.min
myTableView2.tag = Int.max
在委托
和数据源
方法中:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let rowCount: Int
if tableView.tag == Int.Min
{
rowCount = self.dataForTableView1.count
} else
{
rowCount = self.dataForTableView2.count
}
return rowCount
}
使用
标记
值来标识右侧的表视图
。每个UIView
对象都有一个标记
属性,即
您可以这样设置:
myTableView1.tag = Int.min
myTableView2.tag = Int.max
在委托
和数据源
方法中:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let rowCount: Int
if tableView.tag == Int.Min
{
rowCount = self.dataForTableView1.count
} else
{
rowCount = self.dataForTableView2.count
}
return rowCount
}
使用
标记
值来标识右侧的表视图
。每个UIView
对象都有一个标记
属性,即
您可以这样设置:
myTableView1.tag = Int.min
myTableView2.tag = Int.max
在委托
和数据源
方法中:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let rowCount: Int
if tableView.tag == Int.Min
{
rowCount = self.dataForTableView1.count
} else
{
rowCount = self.dataForTableView2.count
}
return rowCount
}
使用标记
值来标识右侧的表视图
,就这样。1)为两个表视图使用不同的委托和数据源
或
2) 为您的两张桌子创建插座并进行比较。委托和数据源方法传递对表的引用
范例
@IBOutlet weak var table1: UITableView!
@IBOutlet weak var table2: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.table1 {
// something
}
if tableView == self.table2 {
// something else
}
}
1) 为两个表视图使用不同的委托和数据源
或
2) 为您的两张桌子创建插座并进行比较。委托和数据源方法传递对表的引用
范例
@IBOutlet weak var table1: UITableView!
@IBOutlet weak var table2: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.table1 {
// something
}
if tableView == self.table2 {
// something else
}
}
1) 为两个表视图使用不同的委托和数据源
或
2) 为您的两张桌子创建插座并进行比较。委托和数据源方法传递对表的引用
范例
@IBOutlet weak var table1: UITableView!
@IBOutlet weak var table2: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.table1 {
// something
}
if tableView == self.table2 {
// something else
}
}
1) 为两个表视图使用不同的委托和数据源
或
2) 为您的两张桌子创建插座并进行比较。委托和数据源方法传递对表的引用
范例
@IBOutlet weak var table1: UITableView!
@IBOutlet weak var table2: UITableView!
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.table1 {
// something
}
if tableView == self.table2 {
// something else
}
}
什么是CollectionView
1.It's similar to a UITableView
2.Layout grid instead of columns.
3.Defined by the UICollectionViewFlowLayout.
4.Nees a custom UICollectionViewCell
5.Requires a data source and delegate
它可以有部分,就像TableView有多个部分一样。每个部分中的项目都相当于TableView中的单元格
UICollectionViewCells具有一组背景属性。拖动到单元格中的第一件事将发生在单元格内容视图的顶部。这是一个像空的tabelViewCell的属性。它里面什么都没有,只是一个视图,所以你在视图上面拖动的任何东西都是可见的。例如图像视图、LabelView等
如果启用cell.contentView背景色,则会使其下方的内容变得模糊。在cell.contentView下面是一个叫做cell.backgroundView/cell.selectedBackgroundView的东西。这些视图最初为零,但我们可以用自己的视图填充它们
只需将CollectionViewController拖动到情节提要,并将其标记为初始控制器。查看文档大纲面板(单击Xcode窗口底部的方形),您将看到CollectionViewController附带collectionView,collectionView中有一个collectionViewCell和一个UICollectionViewFlowLayout,用于控制单元格的位置
这是你可以享受所有乐趣的地方。可以在其中放置任何类型的视图。祝你好运
什么是集合视图
1.It's similar to a UITableView
2.Layout grid instead of columns.
3.Defined by the UICollectionViewFlowLayout.
4.Nees a custom UICollectionViewCell
5.Requires a data source and delegate
它可以有部分,就像TableView有多个部分一样。每个部分中的项目都相当于TableView中的单元格
UICollectionViewCells具有一组背景属性。拖动到单元格中的第一件事将发生在单元格内容视图的顶部。这是一个像空的tabelViewCell的属性。它里面什么都没有,只是一个视图,所以你在视图上面拖动的任何东西都是可见的。例如图像视图、LabelView等
如果启用cell.contentView背景色,则会使其下方的内容变得模糊。在cell.contentView下面是一个叫做cell.backgroundView/cell.selectedBackgroundView的东西。这些视图最初为零,但我们可以用自己的视图填充它们
只需将CollectionViewController拖动到情节提要,并将其标记为初始控制器。查看文档大纲面板(单击Xcode窗口底部的方形),您将看到CollectionViewController附带collectionView,collectionView中有一个collectionViewCell和一个UICollectionViewFlowLayout,用于控制单元格的位置
这是你可以享受所有乐趣的地方。可以在其中放置任何类型的视图。祝你好运
什么是集合视图
1.It's similar to a UITableView
2.Layout grid instead of columns.
3.Defined by the UICollectionViewFlowLayout.
4.Nees a custom UICollectionViewCell
5.Requires a data source and delegate
它可以有部分,就像TableView有多个部分一样。每个部分中的项目都相当于TableView中的单元格
UICollectionViewCells具有一组背景属性。拖动到单元格中的第一件事将发生在单元格内容视图的顶部。这是一个像空的tabelViewCell的属性。它里面什么都没有,只是一个视图,所以你在视图上面拖动的任何东西都是可见的。例如图像视图、LabelView等
如果启用cell.contentView背景色,则会使其下方的内容变得模糊。在cell.contentView下面是一个调用