Contained UITableView's Height always 44.0 - ios

I am trying to create a button like UIControl that looks like the standard UITableViewCell and support the CellStyles of Value1, Default and Subtitle.
I did try simply creating a UITableViewCell and adding it as a SubView of my UIControl but unsurprisingly the cells don't behave as expected when not in a UITableView.
So I now have a table in my UIControl that has a custom Table DataSource that is hardcoded to only one row.
When I create the cell I populate the text values of the TextLabel and DetailLabel.
This works fine in most cases but when my UIControl is arranged in a UIStackView it is refusing to size the table/cell's height any greater that 44.0.
I am using the CellStyle SubTitle and setting the Labels to be Multilines. They do wrap but appear outside of the Cell which appears fixed to 44.0.
I have set EstimatedHeight on Table and AutomaticDimension
Can anyone offer any suggestions as to why this might be.
Sent from my iPhone

Related

Only first collectionViewCell reacts to user interactions

The setup
I have a rather complex view hierarchy which made me do terrible things with tableViews and collectionViews. Right now I'm having a regular grouped TableView with custom TableCells. TableCell itself contains a couple of views and a Collection View. The height of the table cell is calculated based on number of items in the data source. On its creation table cell creates a collection view with a calculated size to fit necessary data.
-- UITableView
---- UITableViewCell
------ UICollectionView
--------- UICollectionViewCell
The problem
I've encountered unusual problem with a custom collectionViewCell. I have a vertical single-column collectionView with dynamic amount of cells. Ideally tapping on the cell should call didSelectItemAt. The cell also has three buttons. Tapping on the button should trigger some action. All of the desired functions work only for a first cell. The rest of the cells are not responsive to any actions.
Things that look strange
By default the scrolling of a collectionView inside of the tableViewCell is disabled because it basically fits all the content based on calculated height and doesn't require scrolling. (Also I don't want it to interfere with tableView scrolling logic).
First
I've tried to hardcode some value for the height of collectionView and enable scrolling. What happened is a mystery for me.
Let's say that calculated height required for the collectionView to show all the content without scrolling is 740. When I manually set it to be 280 (this is enough for exactly 2 cells to fit) and enabled scrolling my first cell were still working, but also when I scrolled collection just a little bit my second cell started to act normally as well. When I scrolled back to the top of the collectionView it was disabled once again.
So it looks like when the scrolling is enabled and will actually occur because of insufficient height to fit the content, cells behave as they should. As soon as I set height of the collectionView to be enough to fit its content, things go wrong.
Second
In some cases I can actually tap on the second cell and it will call the delegate. But the weird thing is it works when I tap in the top area of the cell, like 10pts from the top. The other areas of the cell are unresponsive so are the rest of the cells in the collection.
The working delegates and buttons with enabled scrolling forces to think that this has nothing to do with delayed or canceled touches. The frame for collectionView and height of the table cell are calculated properly as well.
xCode 8.3, iOS9+
As it turned out when I was creating my tableViewCell, I hardcoded the height of the collection to value of 214. The reason for that is very simple. I create a cell programmatically and with tableViewCells created programmatically the height of the cell is always 44. When you override init(style: UITableViewCellStyle, reuseIdentifier: String?)
You need to either hardcore the height, or update it in cellForRowAtIndexPath. Even though I updated collection frame when it was filled with data, the container view of this collection wasn't updated resulting in some sort of clipping area for user interactions.

What should I do to set up the constraint on UICollectionView

I have a tableview which shows the news. And there's a UICollectionview inside each UITableview cell. Also there'll be some images inside collection view cell and the number of cells cannot be fixed because news may contain one image, two images or more.
The
UITableview cell looks like the following structure :
xxxxxxxxxxxxxxxxxx
name
news info
(UICollectionview img1 img2...)
UIButton and UILabel (such as like, dislike, comment..)
xxxxxxxxxxxxxxxxx
and I also set up the constraints. And I have to set up the width attribute for the UICollectionview. The main issue is that no matter how many images I may have for the news, the collection view will be always that wide and will block the click event for the tableview cell. So any ideas for that,
thx!
here is a suggest:
set the initial width constraint to 0, then changing it to actual width when bind data to cell.

ios tableView clearColor seperator

I have set my tableView's background color, and I want there is space(10px) around each cell show that color.
e.g.(ignore the red line)
What I am doing now is make the cell embed a smaller view, and set the cell's background to be clear. But it is annoying to create such embed view again and again.
So, I am seeking for a better solution, I believe it would be good if i can increase separator's height. But the old answers did not solve my problem.
(How to increase the UITableView separator height?)
EDIT:
However, if I add my own separator in cell. I may not able to set the cell having round corner
Set the tableView's separatorStyle to .None.
Create a custom UITableViewCell subclass.
In the storyboard (or xib if you created one for the custom cell), add a subview that's inset the amount that you want padded on all four sides.
If you want rounded views, do that on the custom cell's subview (e.g. subview.layer.cornerRadius = 10.0, subview.layer.masksToBounds = true).
Set the custom cell's ContentView to have a clear background.
Set the table view's background to that lovely shade of blue.
Set the cell subview's background color to white.
You don't have to use the cell repeatedly in InterfaceBuilder. Just give the cell an ID, and in your implementation of the table view's data source, dequeue a cell instance using that ID and set the values of the labels inside it.
Have you thought of just making the cell height taller and putting your own separator on the bottom of your custom cells? Nice table layout by the way.

UIFooterView not showing when using deque Reusable cell with identifier to get UIView

I am trying to add a footer to my UITableView. I was able to do this programmatically by making a new UIView with the desired height and width and setting the tableView's tableFooterView to this view.
However, I want to use a reusable tableView cell as my table footer. I tried to set the property as follows
myTable.tableFooterView = myTable.dequeueReusableCellWithIdentifier("footerCell") as UIView!
However, the table View does not show up. I was able to get it working when implementing the tableViewforSection delegate method. However, I realized that I need a table footer and not a section footer, since I'm effectively trying to create a custom last cell for my table that scroll with it.
PS: I checked the identifier for my footer cell in storyboard and it looks correct. I also tried creating a custom class for my custom cell and setting the storyboard cell to be of that type, but that doesn't work either.
If you want to use a cell for your footer, and you're using an array to populate your "regular" cells, then return the array.count + 1 in numberOfRows, and put an if clause in your cellForRowAtIndexPath to check if indexPath.row == array.count. If so, dequeue your footer cell.

UITableViewCell selection behaviour changes when selectedBackgroundView is set

I have a UITableViewCell which is loaded from a xib, with a handful of labels and image views. I notice that when the .selectedBackgroundView property is set (in -awakeFromNib), interaction with the cell is only possible when touching on the labels or image views within the cell.
Trying to touch any blank space in the cell does nothing. Not setting .selectedBackgroundView returns the behaviour to normal.
Does anyone have a fix for this? (Mine currently is to place an empty UILabel over the entire contents of my cell)

Resources