Reputation: 20680
I am trying to create message screen where I put a UITableView in a view with a UITextField and UIButton in its footer.
Problem starts when there is no data or less data for UITableView and its footer reaches to the Top, which should not be, like in below pic.
It suppose to be in the bottom or I could align my UITableView to the bottom as if it has less data atleast footer (which has UITextField and UIButton) should be in the bottom, like in the below pic
I controls hierarchy is like this
Please help, to keep TextFiels and button in the bottom either It has data or NOT.
Upvotes: 0
Views: 945
Reputation: 23233
Under most circumstances, your shouldn't need to put a UITableView
inside a UIScrollView
since UITableView
is already a sub-class of a UIScrollView
.
As for the question you asked. Do you really want the text field and button in the table? When you consider most texting apps you want the text field to always be visible, regardless of scrolling up and down through the messages. As such you might want to take it out of the table and put it on the bottom of the screen below your table. Which would incidentally also solve your problem.
Maybe you REALLY want it as a footer. You can still do it. There are 2 ways to accomplish the task.
Check the combined height of all your rows + height of your footer. If this is smaller than your screen space, increase the height of your footer to fill the rest of the space. You'll have to make sure the text field/button aligned to the bottom of your footer.
// where 'footer' is the view of your footer
CGFloat newFooterHeight;
if (sumRowHeight + defaultFooterHeight < view.frame.size.height) {
newFooterHeight = view.frame.size.height - sunRowHeight;
} else {
newFooterHeight = defaultFooterHeight;
}
CGRect alteredFooterFrame = footer.frame;
footer.frame.size.height = newFooterHeight;
footer.frame = alteredFooterFrame;
Upvotes: 3
Reputation: 9561
Don't include the text view and button in the table. Put them in the root view as a sibling of the table. That way you can position it as always at the bottom of the screen.
Upvotes: 0