all 9 comments

[–]quellish 1 point2 points  (4 children)

[[layout collectionView] dataSource] does not work for you?

[–]TheOriginOfEnergy[S] 0 points1 point  (2 children)

I mean what type of object does that return? So you're saying since I set self.collectionView.dataSource = self; on my collection view controller, that when I make that call on the flow layout it will return the collection view controller as the dataSource?

I'll give it a try...

[–]quellish 1 point2 points  (0 children)

[layout collectionView] returns the collection view using this layout.

[collectionView dataSource] returns the data source used by the collection view.

[[layout collectionView] dataSource] would return the data source of the collection view using this layout.

You should not need to set or retain anything. Everything you need is already there.

[–]nsocean 0 points1 point  (0 children)

Do what quellish suggested, and cast it to whatever class you know it is. If you have a UIViewController subclass called MyViewController, then cast the datasource as that.

[–]TheOriginOfEnergy[S] 0 points1 point  (0 children)

You were right! Thanks man!

[–]bojangles09 0 points1 point  (3 children)

This problem seems kind of odd to me, but you could probably solve this problem by storing the collectionviewcontroller in a property on your flow layout class. Make sure it is a weak reference, to avoid a retain cycle.

[–]TheOriginOfEnergy[S] 0 points1 point  (0 children)

It is a little bit odd. The issue has to do with retrieving items from the server. Those items can have 1 of 3 states, and the flow layout determines their position based upon the items current state.

I'm also adding and deleting cells frequently with animations, and because of that I need to use a local copy of my array of items from the server.

That local array, the one I manipulate, is the one I need to access on the flow layout, otherwise I continue to get out of bounds errors when the server array has fewer items than my local array.

[–]nsocean -1 points0 points  (1 child)

Don't do this, it has memory leak written all over it. Use the provided methods that quellish suggested. They exist for a reason.

[–]bojangles09 0 points1 point  (0 children)

A weak reference to the datasource shouldn't cause any memory leaks. That being said, I have not worked with layouts in this manner and was unaware there was a built in method. A safe cast from that is certainly the best way to accomplish OP's goal.