ios - Vertical position is ambiguous - ios

I've a regular table view and I'm putting a view above and below the cell currently in the middle. On some occasion, those "above" and "below" cells don't appear because Vertical position is ambiguous. I don't see the ambiguity. My views structure looks like
ans here's a screenshot of the contraints on the above cell:
As you can see, constraints related to vertical positioning are:
bottom of the view
height
And I don't see how this leaves room for uncertainty regarding the positioning of this view.

You should not be putting any views inside a table view, either table view cells or other views. You define cell prototypes and then the table view creates and places cells as needed based on the data source.

Related

How do I add spacing in the UITABLEVIEW between cells?

Hi i am new to swift and i am looking for a way to make space between cells.
I have tried different types of code found here but neither works.
How do you make spacing between Cells in the uitableview?
If you are using auto layout, you can embed your cell design inside a view and add top and bottom spacing to that view with respect to content view.
Consider below screenshot, the red coloured view contains all the design and have top and bottom spacing with content view.

How do I change the horizontal spacing between cells in a horizontal scroll collection view

I have a collection view which is basically a horizontal table view. It's one line of cells that scrolls left and right. Sort of like a carousel without the fancy animation. I would like to be able to control the distance between cells. There is a property for doing that in the interface builde. It is in the collection view flow layout, in the inspector (in the tab with the little ruler where you usually see constraints). It is called Min. Spacing and has two variants: For Cells and For Lines. I changed the value of For Cells but it doesn't affect the spacing. Neither does changing the parameter minimumInteritemSpacing or using the collection view callback for specifying that parameter on a per section basis. Help!
The answer is that in a horizontal scroll collection view, the distance between cells, even the horizontal distance, seems to be controlled by the For Lines parameter (in IB) or minimumLineSpacing parameter of the CollectionViewFlowLayout.
This answer is also buried in some answers I saw more general question about cell spacing in collection views:
https://stackoverflow.com/a/48791318/826946 and
https://stackoverflow.com/a/37420529/826946
I decided to separate it out into a separate question that directly addresses the issue of horitzontal scroll collection views.

TableView horizontal scrolling according to cell width

I have table view inside scroll view which will scroll according to table view cell width.I have set the scroll view from top,bottom,leading and trailing.Then I have given the same constraints to view inside the scroll view including centerX and centerY.Then for horizontal scrolling I have set the trailing and centerX priority to 250.But my table view is not scrolling.I want to set it through autolayout.
I want the table to scroll horizontally if label increases inside the table view cell.
This is my view hierarchy
#Zahid I made a public example on github with what I wrote about below:
https://github.com/amichnia/stack-54735700
Original answer:
As it was already said, table views do not scroll horizontally in general. But no one said you can't put table view inside UIScrollView that scrolls horizontally. There would be some challenges here though:
I don't think autolayout with autoresizing cells would work good.
You need to figure out scrollview/tableview gesture recognizers order. You can use UIGestureRecognizer delegate methods to resolve their collisions
You need to determine width of the table view. You can do it with old nasty way:
compute size of every cell first,
take max of these sizes
set it to table view width
reload data
Is it worth the hassle? That's your call to take.
With your setup (I see scroll view as root view) the simplest (but not best) option would be to disable scrolling on table view, enable scrolling both directions on scroll view, and just update whole table view size. It will work well only with small amount of cells though!

Auto Layout: Set height View depends on other height View

I need to implement AutoLayout in my layout. Below are some screenshots:
1.
2.
The case is :
I have a ShinobiDataGrid in View and a UITableView . First image is first condition, in first picture I want the view have height as height View Controller.
The second and third picture is when there are available TableView . I want the TableView always is at the bottom of View Controller and the View is have height depends of height Table View.
I read this, this and all of reference on that but it's not working for me.
Edit
I read some article about Auto Layout and I get this below:
1.
2.
But in first picture, the the UIView still have a distance with main View. I want it only have 3 or 4 point from bottom of main View like below:
Now, I have one constrain from UIView to the UITableView. I add one constrain from UIView to bottom main View with custom priority, constant and etc but it's not working.
1.I would suggest you to use UITableView with section header and footers , with no scroll. Add your views to UITableViewCell. Populate your UITableView with custom cells based on your requirements.
2.You can also use UIStackView for the same. Add all your views & table views to a vertical stack view in Interface Builder. Keep distribution as fill equally. First time hide your UITableView. Your view will cover complete then show / hide tableview when required and update stack view.
Constraint your views & table views with respect to stack view. UIStackView manages autolayout.
3.I would have used UITableViewController with static cells (with no scroll) with views and tableviews as subview of static UITableViewCells. First time in heightFoRowAtIndexPath pass complete height. When tableview will be visible. Reload tableview controller and pass height accordingly.
Instead of using UITableView inside cell. I would suggest using UIStackView as subview cell. Show your data in UIStackView.
First add scrollview.
Add the height constraint of First View equal to view controller.
Below to that, add the tableview, get the dynamic height and change according to it. You can see my answer here for this.

Scrolling / static UITableView footer

I want to have a UITableViewCell with a behaviour mixed between a section footer and the table footer:
If the table is not filled (meaning there are not enough cells to fill the entire screen), the cell should stay at the bottom of the table, anchored to the screen edge, leaving blank space between itself and those above. (behaving like a table footer)
If the table is filled, the cell should start scrolling and always remain at the bottom of the table. (behaving like a section footer)
I'd like to avoid as much as possible weird tricks to achieve this, is there an elegant solution that allows me to do this?
Make your footer a separate view on top of the tableView with a constraint to the bottom of the tableView and take an outlet to this constraint. Override scrollViewDidScroll and get the bottom y coordinate of the last visible cell by using tableView.visible cells and calling CGRect.maxy on its frame (if there is no last cell your constraint constant is tableView.frame.size.height - footerView.frames.size.height). Take the difference of the tableView.frame.maxY and the last visible cell's maxY. If the cell is past the tableView.frame.maxY - footerView.frames.size.height then you set your constraint constant to 0, otherwise you set it to the difference.
This has the effect of pinning your footer view to the last visible cell, unless this would force the footer past the bottom of the table, in which case you just pin it to the bottom of the table instead. If there is no last cell you pin the footer to the top of the table.

Resources