【发布时间】:2017-05-21 06:53:40
【问题描述】:
编辑:我正在尝试重新创建 instagram/twitter 个人资料页面。因此,如果我目前尝试的方式不起作用,请随时告诉我如何以完全不同的方式重新创建这些个人资料页面。
我已经设置了一个带有标题的 UICollectionView。在这个标题内,有一个 menuBar 有两个不同的选择选项。如果用户选择第一个索引,则 menuBar 返回 0。如果用户选择第二个索引,则 menuBar 返回 1。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! CoverCell
return cell
}
这里是菜单栏和它下面的collectionview单元格的图片:
我也有这个代码来设置单元格:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let menuBarIndex = profileMenuBarSelectionIndex.menuBarIndexSelection
var cell: UICollectionViewCell
switch menuBarIndex {
case 0:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: test1CellId, for: indexPath) as! test1Cell
case 1:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: test2CellId, for: indexPath) as! test2Cell
default:
cell = collectionView.dequeueReusableCell(withReuseIdentifier: test3CellId, for: indexPath) as! test3Cell
}
return cell
}
编辑 2:我现在添加了此代码,其中 myTestAction 是 testAction 在不同文件中的委托函数。
var index: Int = 0
func testAction() {
index = index == 1 ? 0 : 1
collectionView.reloadData()
}
func myTestAction() {
delegate?.testAction()
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
switch indexPath.row{
case 0:
menuBarIndexSelection = 0
menuBarIndexChangeFlag = 1
case 1:
menuBarIndexSelection = 1
menuBarIndexChangeFlag = 2
case 2:
menuBarIndexSelection = 2
menuBarIndexChangeFlag = 3
default:
menuBarIndexSelection = 0
}
myTestAction()
}
我希望能够根据 menuBar 返回的值在标题下方显示不同的单元格。我该怎么做? 或者 如何重新创建 Instagram 个人资料页面?
【问题讨论】:
-
通过分享图片展示你的输出
-
好的,发一张它的样子
标签: ios swift xcode uicollectionview