0

I have created 2 collectionView in my viewController

    SchoolActivitycollectionView = UICollectionView(frame: CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height), collectionViewLayout: flowLayout)
   PrivateActivityCollectionView = UICollectionView(frame: CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height), collectionViewLayout: flowLayout)
    PrivateActivityCollectionView.delegate = self
    PrivateActivityCollectionView.dataSource = self
    SchoolActivitycollectionView.delegate = self
    SchoolActivitycollectionView.dataSource = self

but the problem is in the datasource

> func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    if collectionView == SchoolActivitycollectionView { ..

>

i tried to seperate this 2 collection view i cant. I print out the (collectionView == SchoolActivitycollectionView) it shows false .

i have tried isEaqual() too .

I just cant seperate them ...so i cant set this 2 collectionview independently... How can i give set these 2 collectionview up??

No Idea For Name
  • 11,411
  • 10
  • 42
  • 70
David
  • 73
  • 1
  • 1
  • 4
  • I think my project's structure is a mess..so I m gonna create 2 file and put those 2 collectionview in 2 new viewcontroller.Maybe that will work – David Dec 07 '14 at 09:15

2 Answers2

0

You could try giving the collection view a tag

SchoolActivitycollectionView.tag = 1
PrivateActivityCollectionView.tag = 2

Then compare it

if collectionView.tag == 1 {
    // SchoolActivity
} else if collectionView.tag == 2 {
    // PrivateActivity
}
imas145
  • 1,959
  • 1
  • 23
  • 32
  • the collectionView.tag always return 0...I know how to do now I can create 2 class for those 2 collectionView and make 2 instance here. – David Dec 07 '14 at 09:10
0

The following code

if collectionView == SchoolActivitycollectionView

is wrong.

You should use === instead to compare two references.

WeZZard
  • 3,536
  • 1
  • 23
  • 26
  • Currently, I have no time to build an environment to simulate your situation. But theoretically, '===' should work. Maybe you should try imac145's solution. If that fails, there should be some errors in your collection view generation code. One step further, it will be better that you dispatch two collection views' data sources and delegates logic into separate object. – WeZZard Dec 07 '14 at 09:17