Ich möchte uicollectionview mit dem erweiterbaren Format erstellen. Wenn wir auf die erweiterbare Zelle tippen, sollten mehr in den Abschnitt Zellen geladen werden. Nach erneutem Aufnehmen schließen Sie den Abschnitt. Es ist wie erweitern und kollabieren Abschnitte. Sowohl die Sektionszelle als auch die innere Zelle sind dynamisch.möchte eine Sammlungsansicht in swift3 erstellen
Antwort
Sie müssen so etwas tun.
Erstellen Sie eine Struktur wie diese global, so dass Sie auf diese in // Ihrer Tabelle Methoden zugreifen können.
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()
}
}
Es scheint, dass Ihre Lösung für UITableView ist. Ich will das für UICollectionView. –
können Sie das selbe für collectionview.main tun, hier ist die Struktur. Sie können hier die Methoden der Sammlungsansicht statt der Datenquellenmethode von uitableview verwenden. Ich kann Ihnen eine Demo zur Verfügung stellen, wenn Sie sie brauchen. –
Ja geben Sie bitte –
- 1. erstellen leeres Array in swift3
- 2. Ich möchte eine Combobox in WPF erstellen
- 3. Sammlungsansicht tiling
- 4. Wie programmgesteuert durch eine Sammlungsansicht scrollen?
- 5. Ich möchte eine Bewegung App erstellen
- 6. Wie zwei verschiedene Zellen in UICollectionView in swift3 angezeigt werden
- 7. Range in Swift3
- 8. Bilder dauerhaft in der Sammlungsansicht speichern
- 9. Sammlungsansicht innerhalb der Tabellenansicht Zelle
- 10. Sammlungsansicht Zellen haben eine inkorrekte Inhaltsgröße
- 11. wie man eine URL in Swift3 öffnet
- 12. Wie ich eine schnelle Datei in swift3
- 13. Sammlungsansicht nicht bevölkert
- 14. Wie lade ich eine Sammlungsansicht automatisch neu?
- 15. Unterschied in Sammlungsansicht und Tabellensichtmethoden
- 16. C# - Ich möchte eine Methode, die eine Liste erstellen oop
- 17. Ich möchte eine Zeitreihe von monatlichen Mitteln in Pandas erstellen
- 18. Ich bin neu in Datenbanken und möchte eine Rezeptdatenbank erstellen
- 19. Laden von Videos und Fotos in PhotoLibrary in eine Sammlungsansicht
- 20. swift3 wie navigation viewcontroller
- 21. NSPredicate in swift3
- 22. Animation des Scrollens in Sammlungsansicht in IOS
- 23. func collectionViewContentSize in Swift3
- 24. Button.titleLabel Fehler in swift3
- 25. Sammlungsansicht Zellgröße ändern
- 26. Wie NSColorList verwendet in swift3
- 27. JSONSerialization Fehler in swift3
- 28. Selektor in swift3
- 29. Levenshtein Entfernung in Swift3
- 30. Parse JSON in swift3
Bitte überprüfen Sie diese https://github.com/apploft/APLExpandableCollectionView Und https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views – Rivendell
Diese ist für UITableView Ich möchte dies in UICollectionView tun –
Haben Sie diese Beispiele überprüft? sie files !! – Rivendell