我想用可展開的格式創建uicollectionview。 當我們點擊可擴展的單元格時,應該加載更多單元格的單元格。再次敲打後關閉該部分。 這就像展開和摺疊部分。 部分細胞和內部細胞都是動態的。想要在swift3中創建集合視圖
0
A
回答
0
你將不得不這樣做。
在全局構建這樣的結構,以便您可以在//表格方法中訪問這些結構。
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate{
@IBOutlet var tblView: UITableView!
let arr = [ "dict1":["1":"one","2":"two"],
"dict2":["3":"three","2":"four"],
] as [String : Any]
var arrDict = [[String:AnyObject]]()
var aDict1 = [String:Any]()
var aDict2 = [String:Any]()
var aDict3 = [String:Any]()
var isbuttonTappedForExpand = false
override func viewDidLoad() {
super.viewDidLoad()
aDict1 = ["Tittle": "Quick Start",
"RowKey": "0",
"ValueKey": ["Section0 row0",
"Section0 row1",
"Section0 row2",
]
] as [String : Any]
aDict2 = ["Tittle": "Personal",
"RowKey": "0",
"ValueKey": ["Section0 row1",
"Section1 row1",
"Section1 row2",
]
] as [String : Any]
aDict3 = ["Tittle": "Business",
"RowKey": "0",
"ValueKey": ["Section0 row2",
"Section2 row1",
"Section2 row2",
]
] as [String : Any]
arrDict.append(aDict1 as [String : AnyObject])
arrDict.append(aDict2 as [String : AnyObject])
arrDict.append(aDict3 as [String : AnyObject])
print("Array of dictionaries is\(arrDict)")
print([arr ])
print(arrDict[0]["Tittle"] ?? 2)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
//Then pass your data into tableview delegate methods
func numberOfSections(in tableView: UITableView) -> Int {
return arrDict.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (arrDict[section]["RowKey"] as? String == "0"){
return 0
}
else{
return arrDict.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell:CustomTableViewCell = tableView .dequeueReusableCell(withIdentifier: "cell") as! CustomTableViewCell
let arr = arrDict[indexPath.row]["ValueKey"] as! [String]
cell.btnClickAddMore.addTarget(self, action: #selector(pressButton(button:)), for: .touchUpInside)
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat{
return 100
}
//you will have to add sections first after clicking on sections you will get your cell so here you will make your view for section
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int){
view.tintColor = UIColor .black
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let rect = CGRect(x: 0, y: 0, width: tblView.frame.size.width, height: 100)
let headerView = UIView(frame:rect)
headerView.backgroundColor = .blue
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: "SectionView", bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil)[0] as! SectionViewClass
view.btnClickAdd.backgroundColor = .blue
view.btnClickAdd.tag = section
view.btnClickAdd.addTarget(self, action: #selector(pressButton(button:)), for: .touchUpInside)
view.frame = headerView.bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
headerView.addSubview(view)
return headerView
}
func pressButton(button: UIButton) {
if (arrDict[button.tag]["RowKey"] as? String == "0") {
arrDict[button.tag]["RowKey"] = "1" as AnyObject?
}
else if (arrDict[button.tag]["RowKey"] as? String == "1") {
arrDict[button.tag]["RowKey"] = "0" as AnyObject?
}
tblView .reloadData()
}
}
+0
看來你的解決方案是針對UITableView的。我想要這個UICollectionView。 –
+0
你可以爲collectionview.main做同樣的事情,這裏是結構。你可以在這裏使用集合視圖方法而不是uitableview數據源方法。如果你需要,我可以爲你提供一個演示。 –
+0
是的,請給 –
相關問題
- 1. Swift3:以集合視圖顯示視頻
- 2. 在視圖中創建新集合 - Backbone.js
- 3. 爲集合創建骨幹視圖
- 4. 創建一個集合視圖
- 5. 框架「集合視圖」將在運行時Swift3 iOS10故事板
- 6. 我想從更大的集合中創建對象的集合
- 7. 在集合中創建通用集合
- 8. 使用視圖在Azure搜索服務中創建集合
- 9. 創建swift3
- 10. 在Android中創建複合視圖
- 11. 在SOLR中創建集合
- 12. 在雲中創建集合
- 13. 集合視圖單元格不顯示在集合視圖中?
- 14. 創建的集成視圖
- 15. 從集合創建集合?
- 16. 想要在drupal中創建狀態組合框塊
- 17. 在滾動視圖中創建1000個視圖需要時間
- 18. 想要合併kinect骨骼視圖與kinect RGB視圖
- 19. swift3如何爲已經創建的視圖控制器創建xib
- 20. 想與動態值創建視圖
- 21. 從集合視圖中刪除集合視圖單元格Xcode
- 22. 我想創建一個Python集合交集的列表
- 23. 在視圖中創建聚集/非聚集索引
- 24. 在Kinvey創建集合(Android)
- 25. 在視圖中創建一個視圖
- 26. 單擊集合視圖中
- 27. 想要根據SAS中的varibale創建一些數據集
- 28. 我需要創建一個彈出式菜單,我可以在集合視圖單元格按下時更改集合視圖中的數據。
- 29. 想要創建佈局
- 30. 想要創建序列號
請這些 https://github.com/apploft/APLExpandableCollectionView 而 https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views – Rivendell
這是UITableView我想在UICollectionView中做到這一點 –
你檢查了這些例子嗎?他們檔案! – Rivendell