UICollectionView cells not showing when I set the height too low - ios

I'm trying to add a UICollectionView to my view to use as a scrolling date picker on a single line. I'd like this to be relatively compact, but I'm having trouble when setting the collection view's height in IB.
Basically if I drop the height of the frame below 114, my prototype cells disappear, and no cells are displayed when I run the app. As long as it's above that value, everything works fine.
I've also got a black bar of empty background space above the cells despite setting their height to the same as the frame's height in sizeForItemAtIndexPath.
My delegate and datasource are set up correctly, and my cell has an identifier set and is being dequeued just fine, as long as the view's height is large enough. Do I need to subclass UICollectionViewLayout to get a really short view to work?

Uncheck Adjusts Scroll View Insets on your view controller or set automaticallyAdjustsScrollViewInsets property on the view controller to false programmatically.

Related

Tableview in scrollview when tableview content size increase then textview just below the tableview goes up to the tableview

I have Viewcontroller in which I set the scrollview. In the scrollview I have tableview which is in the Container and just below the container I have an textview and some other UIViews when I set the tableview frame size equal to content size and tableview scroll property false so that only scrollview scrolls when the content size increase the textview goes up to tableview and I want that when tableview content increase then textview also goes down and parent view frame size increase and decrease as the content size
This look like a job for a UICollectionViewController. If you want to take a look here
you can get a better understanding of what they are and how to use them.
Basically you want to put each of those UITableViews, UILabels and the UIButtons in it's own cell(buttons need to be arranged) of the collectionView then the cell with the buttons try to use a stack view with the image. This will automatically set the different sections apart from each other. I know the idea of a collectionViewCell containing a tableView may seem weird but check this out
Another solution is to get crazy with constraints and autoLayout. I don't recommend this route because autoLayout will make decisions on it's own if the exact layout is not explicitly declared. Basically you'll set the constraints by pinning the tableView and labels to each other and the container they are in.
Checkout Apple's docs here
Good luck and let me know how it goes
I would recommend using a xib (if storyboards is your preference) or programmatically embed a tableview in the Scrollview Controller. Set a default cell height and then calculate the height of the Tableview by grabbing the amount of cells (which you'll normally get from .count in an array).
Afterwards, constrain the top, left, and right constraints of the tableview to its parent. You can imbed these in a scroll view for ease. Then if you want default text underneath it, all you have to do is constrain the top of the textview to the bottom of the tableview.
Do the cell for the button's. As the post above said, buttons might be best done in a CollectionView, so you can either create a default cell (xib again is useful) or use a prototype cell in storyboard. Collection views are the same principle as tableviews when it comes to populating data, they are just formatted differently and insets/spacing between cells.
This should help!

Unable to move cell up in uicollection view from storyboard?

I have added UICollectionView.I have also added the Cell in the UICollectionView.The issue is cell always getting space from top of 74.On interface builder the y space column always shows the disabled value please tell how can i remove such issue?
Any given cell's position is determined by the collection view. You can adjust the cell's insets to increase spacing between cells and the scroll view's insets to position all of the cells in the scroll view, you can't directly manipulate a cell's position out of the box. When noting the position of your first cell you should also take into account whether your viewController has extend edges under top bars on and whether it has adjust scroll view insets on.

UICollectionView rendered taller than in storyboard

I have a UICollectionView in a storyboard (iPad). I'm not setting any properties (margins, sizes etc.) programatically - my delegate only implements the mandatory methods (number of sections & items, cellForItemAtIndexPath). I'm using the standard flow layout, with horizontal scrolling (1 row), and no top/bottom insets. I have a custom cell class, but again, nothing fancy (just IBOutlets for some labels and an imageView). My cells are 100x100px. The collectionView has its height set to 100px, and IB shows it as such.
However, when I run the app I get the collectionView rendered as 140px in height (with a 20px margin above and below the cells). I played with different values for all properties (including the min spacing) but couldn't make the view any shorter - I can only make it taller by changing the insets.
Is this a bug or am I missing some logic that I cannot circumvent, e.g. the standard layout will forcefully include some minimum spacing above & below its contents?
For me the solution was to disable "adjust scroll view insets" on the view controller that has the collection view.

UITableView inside the UIScrollView for horizontal scrolling does not work as expected

I use a table view which has got the cells with varied set of information and which can not be contained with in the frame of the tableView. So I do need to have a horizontal scrolling capacity in the table view.
Since horizontal scrolling is not possible with tableview,I planned to use a scrollView with horizontal scroll. I added the tableView on top of the scrollView.
The problem I face is irrespective of the content size property of the scrollview, the scrollview never scrolls beyond the contentOffset value X of 256-320 pixels.
I am planning to achieve the effect as it is in the below screen shot
Try two things,
First Set the TableView height as total numberOfRows :
tableView.frame.size.y = numberOfRows * 44;
now disable the tableView Scrolling
and set he scrollView contentSize as per your need;
scollerView.contentSize = numberOfRowsintableView
Surely it will solve your problem
Set proper ContentSize for ScrollView in ViewDidLoad.
scollerView.contentSize = CGSizeMake(Width,Height);
Calculate the Width as Per Requirement And Height (you are using Tableview So You can take Height same as View Height)
Then it will Surely Scroll.
I implemented the entire functionality using code without using interface builder. It works as expected now. I did not know why it did not work when used with interface builder.

UITableView scrollable content size

I am trying to achieve a newsstand like effect with a scrolling and repeating background. I could do this using a UITableView if I could set it's content size (An inherited method that seems to be overridden by something else in the UITableView Code) in order to fill the view with unscrollable cells.
Currently I am planning to make a custom uiscrollview. Which will be more complex and won't have the cell reuse.
So, is there a way to set a UITableView's content size.
You could semi-hack a 'contentSize' kind of control over a UITableView by simply setting the number of cells that you have (let's assume you have a 1 section table view and aren't using a 'grouped' styled table) to:
your desired height contentSize height / height for each cell (default is 44)
Now, your problem is that if you only have, say, three rows' worth of data to display, what to do with the rest of the cells? Well, simply set their backgroundColor to the same as the table's background color and their selectionStyle property to UITableViewCellSelectionStyleNone. Wham, now you have invisible cells, and can set the 'contentSize' of the table.
Note that your contentSize will only have a resolution of the height of your cells, if you leave the cell heights at their default 44, then you can only set the contentSize to a multiple of 44.

Resources