uicollectionviewcell

Specify row and column number for UICollectionView

拜拜、爱过 提交于 2019-12-05 12:44:17
问题 I want to show a UICollectionView which contains exactly 2 rows and 100 cells in each row. // 1 - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { return 100; } // 2 - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { return 2; } // 3 - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell"

could not dequeue a view of kind: UICollectionElementKindCell with identifier

有些话、适合烂在心里 提交于 2019-12-05 12:35:13
I have UICollectionView, but it seems that I set up everything right. But I get the error: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier PeopleCellForList - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' My storybord: My code is: @interface PeopleCellForList : UICollectionViewCell @end @implementation PeopleCellForList @end #pragma mark - UICollectionView Datasource - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { return self.arrayPeople.count; } - (NSInteger

UICollectionVIew inside a UITableViewCell how to get dynamic height with autolayout

只谈情不闲聊 提交于 2019-12-05 12:07:14
I know that there is a similar question , but I'd like to give more hints about how I tried to achieve that since the original question doesn't give any advice. I have a UITableViewCell as a subview of the contentView there is a UICollectionView , I'd like to have the cell height in function of the collectionview contentSize , the table view cell is the collection view delegate and datasource. The collection view should be fixed without scrolling possibilities in a vertical flow and it should adapt its height on the number of cell lines. To do that I've tried to used the same technique I use

how to use center vertically cells in collection view in paging mode in swift 4?

两盒软妹~` 提交于 2019-12-05 11:48:17
I read How to vertically center UICollectionView content But when I used the codes here func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { let navBarHeight = self.navigationController?.navigationBar.frame.height let collectionViewHeight = (self.collectionView?.frame.height)! - navBarHeight! let itemsHeight = self.collectionView?.contentSize.height let topInset = ( collectionViewHeight - itemsHeight! ) / 4 return UIEdgeInsetsMake(topInset ,0, 0 , 0) } But when scrolling collection view

iOS: UICollectionViewCell auto adjust size according to screen size

送分小仙女□ 提交于 2019-12-05 10:34:46
I am trying to create 10 cells in the collection view(same size as the screen). When I run my app in iphone5s simulator, the view contains exactly 5 cells. But when I switch to iphone6p simulator, the view contains more than 5 cells. How should I adjust the cell size so that the number of cells in screen are consistent across different screen sizes? Britto Thomas -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { int numberOfCellInRow = 3; CGFloat cellWidth = [[UIScreen mainScreen]

Fast Enumeration through UICollectionView Cells - Swift

半城伤御伤魂 提交于 2019-12-05 07:18:50
I am trying to fast enumerate through all of my collection view cells, however this implementation below is giving me a warning. for cell in self.collectionView?.visibleCells() as [UICollectionViewCell] { // Do Stuff } Error below appears on first line: Operand of postfix '?' should have optional type; type is '(UICollectionView, cellForItemAtIndexPath: NSIndexPath) -> UICollectionViewCell' I've tried messing around with optionals and had this working in Xcode 6 Beta 6, but to no avail in "Beta 7" How do i get rid of this error? / Write a loop that goes through all my CollectionView Cells ?

What's wrong with register(_:forCellWithReuseIdentifier:) on UICollectionView?

£可爱£侵袭症+ 提交于 2019-12-05 06:58:56
I'm working with an UICollectionView . As dequeueReusableCell(withReuseIdentifier:for:) expects You must register a class or nib file using the register(_:forCellWithReuseIdentifier:) method before calling this method , I added a line in my viewDidLoad func as self.collectionView!.register(PhotoCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) Now when I'm using the cell for dequeuing and configuring, I'm getting error and app crashes. fatal error: unexpectedly found nil while unwrapping an Optional value This is my DataSource method: override func collectionView(_

UITableViewAutomaticDimension not working on iOS 8

五迷三道 提交于 2019-12-05 06:48:17
I was following this tutorial to make self sizing cells. I registered custom cell into table view and in the cell xib I gave every subview constraints manually. Please refer to the source code in GitHub Arranging 3 labels vertically in one cell's content view worked fine in iOS 9 but not in iOS 8 (both tested in device and simulator). In iOS 8 one cell does not have fitting height and not every label shows all it's full text. iOS 8 not fitting: iOS 9 as I expected: Any advice would be appreciated! Update code in viewDidLoad : tableView.registerNib(UINib.init(nibName: "SelfSizingCell", bundle:

How to compare a color in swift

ⅰ亾dé卋堺 提交于 2019-12-05 05:05:50
I am trying to compare colors but I cannot use the isEqual method because I am trying to compare the color of the background of a UICollectionViewCell . What is the correct way to compare colors in this situation? if(cell!.layer.backgroundColor! == UIColor.redColor().CGColor) { cell?.layer.backgroundColor = UIColor.redColor().CGColor } Try CGColorEqualToColor(_ color1: CGColor!, _ color2: CGColor!) -> Bool . I've come up with this in a playground, I've assigned the backgroundColor property of the UICollectionViewCell with a UIColor and then created a UIColor from it's layer.backgroundColor

How to add uibutton action in a collection view cell?

寵の児 提交于 2019-12-05 00:34:35
问题 So I have this collection view with cells containing an edit button, located on the upper right corner. How do I wire up an action into it? I tried adding cell.editbutton.addTarget in collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell But it doesn't detect the touchUpInside Event. 回答1: May be needful for you- Write this code in cellForItemAtIndexPath Swift 2.X let editButton = UIButton(frame: CGRectMake(0, 20, 40,40)) editButton