David
David

Reputation: 73

[ios8 (Swift)]I add 2 collectionview to my viewcontroller but i cant seperate them in the delegate and Datasource..How?

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??

Upvotes: 0

Views: 232

Answers (2)

WeZZard
WeZZard

Reputation: 3556

The following code

if collectionView == SchoolActivitycollectionView

is wrong.

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

Upvotes: 0

imas145
imas145

Reputation: 1979

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
}

Upvotes: 0

Related Questions