UICollectionView's cell disappearing
So, what did work?
1) Subclass UICollectionViewFlowLayout
.
2) Set the flowLayout of my UICollectionView
to my new subclass.
3) On the init method of the UICollectionViewFlowLayout
subclass, set the orientation you want:
self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
In my case it is Horizontal.
4) The important part:
-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
return YES;
}
At this moment, I should theorise a bit, but honestly I don't have a clue.
Why is text on a UICollectionViewCell disappearing when tapped on?
I would make sure the label is added to the contentView
of the cell and not just the "top-most" view of the cell. Maybe the way the xib
is setup is not right. Make sure it is UICollectionViewCell
in the xib etc. You could also post pictures of how you have setup the xib
.
Also, to debug, I would remove any code that deals with the cell that is not revolved around the label (for example, remove the animations until you fixed the bug). That will allow you to zone in on the issue. Or, another way, just begin from scratch and re-create the cell (with only the label). Getting a label to display is not rocket science, but you can make it rocket science if you do not build what is going on step-by-step.
Another potential issue is layout. Is the layout done right? And maybe it breaks (for some reason) when you highlight.
Cells disappearing with horizontal scrolling in UICollectionView
Silly, silly rookie mistake. Leaving this here if anyone else needs glasses like I do :)
The collection view did not have an horizontal constraint...
addSubview(gallery)
gallery.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true
gallery.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
Correcting this to
addSubview(gallery)
gallery.topAnchor.constraint(equalTo: label.bottomAnchor).isActive = true
gallery.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
fixed it (obviously).
Cell disappearing after scrolling 2 - 3 times in UICollectionView
Here I am answering my own question.
As I am stuck for the last 2 days on this issue.
As I am using CollectionViewController
and add that Controller
view into my current using controller so it's disappearing my collection view cell.
Reason: due to
ARC
releasing thatdelegate
&datasource
connection and that collection view can't able to get cell while I am
scrolling from top to bottom.
Solution:
I solve this problem in 2 ways.
1st : Create that CollectionViewController
in my current VC
not in Service & JSON
Parser class due to delegate & datasource
connection loss.
The most important part in the below code is addChildViewController
by this it will not releasing delegate connection and works as expected.
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
CardListViewController *objCardListViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:@"CardListViewController"];
objCardListViewController.view.frame = CGRectMake(0, 0,self.cardMainView.frame.size.width, self.cardMainView.frame.size.height);
[self.cardMainView addSubview:objCardListViewController.view];
[self addChildViewController:objCardListViewController];
but as per my requirement I needed this collection view at many places
so I need to generalize this collection view.
So I choose the 2nd way which is ContainerView
with add child controller and I connect this CollectionViewController
with container view so I can use it as many places where I need this list.
Strange but true.
Hope this will help someone if facing the same issue.
Thanks & Happy Coding.
Related Topics
How to Add a 'Done' Button to Numpad Keyboard in iOS
Real Time Blur Effect for Navigation Bar
How to Rotate Orientation Programmatically in Swift
Ios: Disable Autorotation for a Subview
How to Give an "Identifier" to a View Controller Within My Storyboard
How to Determine Height of Uicollectionview with Flowlayout
How to Differentiate Between Iphone4 and iPhone 3
Uialertview/Uialertcontroller iOS 7 and iOS 8 Compatibility
How to Simultaneously Satisfy Constraints - No Constraints in Place
How to Implement Auto-Complete for Address Using Apple Map Kit
Open Phone Settings Programmatically in iOS9
Switch Cameras with Avcapturesession
Nstimer Timerwithtimeinterval: Not Working
iPhone Core Data "Automatic Lightweight Migration"
What's the Difference Between "Architectures" and "Valid Architectures" in Xcode Build Settings
How Does Apple Notify iOS Apps of Refunds of In-App Purchases (Iap)