0

I need to implement AutoLayout in my layout. Below are some screenshots:

1.

enter image description here

2.

enter image description here

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.

enter image description here

2.

enter image description here

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:

enter image description here

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
MrX
  • 953
  • 2
  • 16
  • 42
  • So, to dumb it down for me: (1) Screenshot #1 - first condition - a single `UIView` with the height of it's view controller. (2) Screenshot #2 - and #3? - to have a `UITableView` - which is basically a view, right - be *below* a `UIView`? What is confusing for me is your use of wanting the table view always down below a `UIViewController`. They may have a base view, but when talking auto layout, a view controller is basically meaningless. Almost as important is your last bit of *its not working for me*. Could be post more details of that - and please, do it by editing the question. Thanks! –  Jul 25 '17 at 03:04
  • @dfd I dont understand which part that you `not working for me` . Someone give the answer right at my prroblem point. I think i dont need edit it Thanks – MrX Jul 25 '17 at 03:51
  • Glad someone helped you. Still wished I understood what you meant - in detail - by something "not working for you". –  Jul 25 '17 at 05:08

2 Answers2

1

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.

luckyShubhra
  • 2,731
  • 1
  • 12
  • 19
0
  1. First add scrollview.
  2. Add the height constraint of First View equal to view controller.
  3. Below to that, add the tableview, get the dynamic height and change according to it. You can see my answer here for this.
Balasubramanian
  • 5,274
  • 6
  • 33
  • 62
  • Should I add `scrollview` ? . I dont want that two (`view` and `tableview`) scroll together – MrX Jul 25 '17 at 03:52
  • You have stated that in first picture I want the view have height as height View Controller. So tableview comes out of the screen. am I right ? – Balasubramanian Jul 25 '17 at 03:56
  • In first picture, I hide the `tableview` from code, not come out. I think it possible without scrollview right? – MrX Jul 25 '17 at 03:59
  • Yes. But if your tableview has more data, then it goes out of the screen. For this purpose we need to add scrollview. – Balasubramanian Jul 25 '17 at 04:01
  • No it will not. I have static data. Look the second and third picture, my `tableview` only have max 6 row. – MrX Jul 25 '17 at 04:03
  • what is the problem are you facing now ? – Balasubramanian Jul 25 '17 at 04:05
  • I have 6 data in `tableview` and there are states for the `tableview`. So i hide the row with `height to 0` . – MrX Jul 25 '17 at 04:05
  • My problem i cant set the height of `view` depends of `tableview`, and the `tableview` cannot in the bottom of controller too. – MrX Jul 25 '17 at 04:06