拡張可能な形式でuicollectionviewを作成したいと思います。 拡張可能なセルをタップすると、セクション内でさらに多くのセルが読み込まれます。テーピングした後、再びセクションを閉じます。 セクションの展開と折りたたみに似ています。 セクションセルと内部セルの両方が動的です。swift3でコレクションビューを作成したい
答えて
このようなことをする必要があります。
このような構造をグローバルに作成すると、//これらのテーブルメソッドにアクセスできます。
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()
}
}
あなたのソリューションはUITableView用のようです。私はUICollectionViewのためにこれが欲しいです。 –
collectionview.mainのために同じことを行うことができますここではstructure.you uitableviewデータソースメソッドの代わりにコレクションビューメソッドを使用することができます。私は必要な場合デモを提供することができます。 –
ありがとうございます –
- 1. swift3でラジオグループを作成する方法
- 2. ターゲットセレクタがSwift3で動作しない
- 3. プログラムで作成されたコレクションビューで画像ビューが表示されない
- 4. swift3の別のViewControllerにcollectionViewデータを送信する方法は?私は私のコレクションビューのデータ(list.assets_id)にしたい
- 5. CoreDataサブクラスで新しいプロパティを作成できませんか? iOS8 Swift3
- 6. スウィフトで5 * 8コレクションビューを作成する方法
- 7. コレクションビューのセルにラベルのコンセントを作成できません。
- 8. 単一列でコレクションビューを作成する方法は?
- 9. エラーを生成するボタンのチェックを作成する(swift3)
- 10. 多くの型の変数をswift3で作成する
- 11. playgroundでImageViewを作成すると、swift3プレイグラウンドがパス
- 12. swift3でエレガントにするためにオプションのアンラップを作成する方法
- 13. Swift3拡張機能で作成されたプロパティを設定する方法
- 14. swift3でtableviewとsearchbarcontrollerを使用してスコープ検索を作成する方法
- 15. テーブルビューのネストされたコレクションビューは、より優れたコレクションビューまたは複数のコレクションビューです。
- 16. は、私がprogramically作成した複数のセルを持つコレクションビューを持っているCollectionViewCell
- 17. コレクションビューのカスタム詳細ビューを作成する
- 18. コレクションビューの複数のデータソースを作成する方法は?
- 19. コレクションビューのセルを押したときに、コレクションビューのデータを変更できるポップアップメニューのように作成する必要があります。
- 20. 私はswift3で委譲者としてシングルトンクラスを作成するにはどうすればいいですか
- 21. swift3 firebase内でappend関数が動作しないobserveSingleEvent
- 22. コレクションビューでImageView.contentModeが機能しない
- 23. y軸に沿ってcameraOverlayViewを作成する方法(swift3)
- 24. Swift3でカレーされたクロージャ?
- 25. コレクションビュー(ドラッグ可能なUICollectionViewCellの作成)致命的なエラー
- 26. UIセグメント化されたコントロールがコレクションビュー内で機能しない
- 27. 他のコレクションビューにdidselectitemを選択した後、コレクションビューからナビゲートする方法
- 28. コレクションビューでスティッキーな水平スクロール効果を作成する方法Swift 3
- 29. コレクションビュー
- 30. JSON Swift3としての文字列swift3
これら https://github.com/apploft/APLExpandableCollectionView そして https://www.raywenderlich.com/99087/swift-expanding-cells-ios-collection-views – Rivendell
これを確認してくださいUITableView用ですUICollectionViewでこれを行いたい –
これらの例を確認しましたか?彼らはファイル! – Rivendell