0

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

mfaani
  • 33,269
  • 19
  • 164
  • 293
TungVuDuc
  • 11
  • 1
  • 6
    see [here](http://stackoverflow.com/questions/29734954/how-do-you-share-data-between-view-controllers-and-other-objects-in-swift) and [here](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – mfaani Dec 19 '16 at 20:18
  • Also see [here](https://stackoverflow.com/documentation/ios/434/passing-data-between-view-controllers#t=201612192205593320018) from documentation – mfaani Dec 19 '16 at 22:06
  • In my case, I just have one ViewController – TungVuDuc Dec 20 '16 at 03:23
  • https://github.com/tarsVEVO/Myproject here's my project, pleasee check it and help me – TungVuDuc Dec 20 '16 at 04:10
  • The links I shared APPLY to passing data between 2 classes. They **don't** have to be of type `viewController` for them to work. So passing data from tableview to another viewcontroller is a good application of the links I sent. Having that said, "Tapped an option in the menu" means where exactly? The red bar at the bottom of your image?! What is link Result? – mfaani Dec 24 '16 at 11:43
  • Do you mean you want to change the entire tableView when a user, using tab bar, clicks and goes to another tab—how can you change the tableView? It's really confusing of what you want to do. Your title just says pass data, but pass data between what and what? – mfaani Dec 24 '16 at 12:02

0 Answers0