See my ViewController
first :
class ViewController: UIViewController, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
var customCollectionView : UICollectionView!
let myMenu : Menu = {
let menu = Menu()
menu.backgroundColor = UIColor.red
menu.translatesAutoresizingMaskIntoConstraints = false
return menu
}()
override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
view.addSubview(myMenu)
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : myMenu]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[v0(50)]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0" : myMenu]))
// Do any additional setup after loading the view, typically from a nib.
}
func setupCollectionView(){
let layout = UICollectionViewFlowLayout()
let frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height-50)
customCollectionView = UICollectionView(frame: frame, collectionViewLayout: layout)
self.customCollectionView.delegate = self
self.customCollectionView.dataSource = self
customCollectionView.backgroundColor = UIColor.white
customCollectionView.register(FeedCell.self, forCellWithReuseIdentifier: "CellID")
view.addSubview(customCollectionView)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CellID", for: indexPath) as! FeedCell
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: self.view.frame.width, height: self.view.frame.height)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
In that ViewController
, I added a menu set in at bottom and a CollectionView
.
And in CollectionViewCell
of CollectionView
I added a tableView
.
My question is: how to change data in the tableView when I tapped an option in the menu?
I can't post image directly because I'm a newbie so this is link Result
In my case, I have one 'ViewController', 'Menu', 'UICollectionViewCell' Class