4

hello friends i am using collection view in iPhone application to show list. I want to set the height of the collection view as per size of my list. how can I set it?

also have the problem when I use set selected method of cell in the collection view it will disable the user interaction.

I don't know what is the reason? Thank you.

Premal Khetani
  • 3,167
  • 1
  • 22
  • 56

4 Answers4

5

"set selected method of cell in the collection view it will disable the user interaction."

this is solved by adding following method.

[newCell setSelected:YES]; 

[collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionNone];

accordingly.

as per given in this link

UICollectionView Select and Deselect issue

Thanks.

Community
  • 1
  • 1
Premal Khetani
  • 3,167
  • 1
  • 22
  • 56
0

try like this,after completion of your collection view you can get content size based on that value you can change frame of collection.

dynamicHeight  =  collectionView.contentSize.height
Balu
  • 8,440
  • 2
  • 20
  • 41
  • 1
    thank you for your reply sunny. But this will set the cell height as per return value. i want to set height of whole collection view. – Premal Khetani Sep 10 '14 at 10:28
  • in that case you can take one global varaible and add heights of each cell to that varaible and then keep it as height of that Collectionview – Balu Sep 10 '14 at 10:29
  • 1
    but where i have to set this dynamic height to my collection view? i mean in which method should i place it? – Premal Khetani Sep 10 '14 at 10:50
  • 1
    and i also use UIViewAutoresizingFlexibleHeight but its not working. – Premal Khetani Sep 10 '14 at 10:58
0

In heightforrowatindexpath try doing this

return [array count]*(your cell's content height);
Baby Groot
  • 4,609
  • 39
  • 50
  • 67
iAnurag
  • 8,752
  • 3
  • 26
  • 45
0

UICollectionView have a different realization other than UITableView, and i recommend to use RZCellSizeManager Or just learn how it works.

Bimawa
  • 3,305
  • 2
  • 20
  • 42
  • this is cell size and this is tableview i want to use dynamic height in uicollectionview. – Premal Khetani Sep 11 '14 at 04:23
  • No. it's support both. This library work like cache of cell. _RZCellSizeManager is an object used to streamline the calculation, caching, and retrieval of sizes for UICollectionView cells and heights for UITableView cells. It pairs particularly nicely with AutoLayout but can be used anytime you want to simplify management of cell sizes._ – Bimawa Sep 11 '14 at 10:54