I am not very experienced with UICollectionView and Auto-Layout.
I have a very basic UICollectionView inside a root view. The root view seems to have a Navigation Item.
I created a custom cell which is really a square in proper size to allow 2 such cells per row using the FlowLayout.
There are 8 such cells in the view - it is basically a grid. I have absolutely no constraints on the view.
The collection view occupies the entire size of the root view according to the IB and in the editor, the first cell is placed right under the navigation item which is perfect.
However, when I ran the app in the simulator and scrolled the collectionview all the way to the button, I see only a partial fragment of both cells in the last row. I can see I have scrolled all the way down...
Obviously there seems to be some sort of overflow...but I would have thought uicollectionview would automatically handle the overflow and make all the cells visible?
When I set number of items in IB I can see that the cells in the last row are only partially visible.
Seems like content size of the collection view is not right - that's my guess..
What do I need to do to adjust things in IB so that all of my cells are visible...I do not want to hardcode any values in the code...
Thanks.
Solved. It turns out simulator does not show the entire collection view...the same shows fine on the device... What a headache...
Related
I have a collection view that is 100 points wide with a number of cells that are each also 100 points wide. I've got it setup to support scrolling and paging horizontally so the user can flick left and right and each cell occupies the entire collection view frame.
Originally, I had no scrolling and the user would tap each cell to activate something in the app. Now that its a narrow frame where only one cell can be seen at a time I feel that tapping is redundant and the cell should simply be tapped in effect when it comes in view.
Is there a way to trigger an event such as didSelectItemAtIndexPath when a given UICollectionViewCell becomes the one displayed within my collection view's frame?
UICollectionView responds to selectItemAtIndexPath:animated:scrollPosition:.
It also responds to indexPathsForVisibleItems which will be useful to determine where to make the selection.
You also need to decide when to make the selection, probably best after receiving scrollViewDidEndDecelerating: which the delegate inherits from UIScrollViewDelegate).
But it may be even better advice to look at what your code does upon selection and just do that (launched from the same place in code, probably when scrolling is finished), leaving selection out of it.
I'm trying to figure out a way to keep a UICollectionViewCell from being removed (didEndDisplayingCell) from my UICollectionView when its original scroll position scrolls off of the view. I know this is the way a UICollectionView is supposed to work, that cells are removed and returned to the reuse pool when they are no longer visible, but this is based on their original position in the UICollectionView. I'm trying to drag that cell past the original visible area into a further away location, but it gets removed killing the pan gesture in progress and killing its view in the collection view once its original position is scrolled out of view. Is there a way to override this behavior and hold onto a UICollectionViewCell until I'm done with it?
I've seen the other ways to attack this problem by creating an image of the cell and dragging that instead, but that won't satisfy my purposes. I need the original cell to survive beyond its original screen position as I scroll through the UICollectionView.
Make copy when dragging your cell around and hide original cell.
How would I go about setting a custom background image for a UITableView. The wrench in the works is that the table is a grouped style (rounded top corners for the first cell and rounded bottom corners for the last cell). I would like do this as much in code as possible without relying on images too much.
Ideally, here is the solution, but I have no idea if this will work or not:
Create one custom background image
Apply the same custom background image to every cell
Rounding occurs automatically because it is a Grouped table style
Profit.
Is this how it works (besides the profit part... I am an app developer, after all)? Do I need to re-think my approach or is this possible? How would do what I described (or another approach) in code specific to iOS 5+?
Update
Just to clarify a bit, the main question I'm asking is: Does the rounding still occur on the top and bottom cells even if you are using a rectangular image?
Well I think what you are saying is ok, but I suggest creating a unique cell layout in a .nib file and apply there the background. Then, with initWithNibName you can manage every cell at the UITableView's methods on the ViewController.
I have a UIViewController. Within it is a UIScrollView with several views inside it. At the bottom is a UITableView.
This UITableView is dynamic and will display either a small number or large number of rows. Either way, I want the UITableView to be displayed full size so the user can scroll down to the bottom of it using the parent UIScrollView, NOT the UIScrollView inside the UITableView.
I've attempted this by disabling scrolling for the UITableView (this works fine). I've then tried at runtime to expand the UITableView so that all rows can be displayed correctly.
However, this part isn't working. For some reason despite the UITableView being really big, not all the rows are being displayed.
I've expanded the UITableView like this:
CGRect frame = tableView.frame;
frame.size.height = 5000;
tableView.frame = frame;
What have I missed? Is there another view inside the UITableView which I need to expand for all the rows to be displayed?
Sorry if this was a silly question, I've only been using iOS for the last month.
Thanks in advance for any help :)
To clarify, this is a screenshot of the problem.
The red area is the UITableView, so it's definitely the correct size. However, there are supposed to be 10 table rows. There are only 5, even less if I increase the size of the table rows.
What do I need to do to display all the rows? What do I need to resize?
While I see you've managed to get it running, placing a UITableView within your own UIScrollView may mean the table view can't manage its content cells as efficiently as it can when it handles its own scrolling.
But, how can you add your own custom views and have them scroll with the table cells? By making them subviews of the UITableView. If you add one or two subviews to a UITableView, it positions them above and/or below its content, and scrolls them with its own cells.
The screenshot below shows how this looks in the XCode interface editor. Note that the root view is the UITableView, it contains two subviews for the header and footer, and those subviews can contain whatever subviews you need.
I managed to get it to work fine. However, I have no idea what the problem was in the first place.
I moved the UITableView higher up so it was covering the other views on the page. It displayed fine. I then moved it down to determine what was causing the problems, and it started displaying perfectly.
I'll put it down to an error in where I placed the UITableView, as I can't see any other issues.
I have UITableView with custom looking cells. Now user can scroll past the bottom and see that there are no more rows (cells) and see background. I want to create impression that there are more rows below, but they should not be added to tableview, so when user scrolls down, it bounces back to last useful cell.
TableFooter and subview expands content and user can scroll there (or maybe I was doing it wrong).
Right now I added new empty cells and after any action that may recount contentSize I specifically set contentSize to default setting. But I feel like it's not the right way (although it works). Is there some other way?
I tried searching, but it's hard to explain what I want in few sentences, not to mention in search line.