Using sizeToFit method on a UITableView
I'm having trouble altering the size of a UITableView control at runtime using the sizeToFit method...in short, it doesn't make any change to the size of the control.
I have a simple quiz app, which serves several multiple-choice questions to the user, with each question having differing numbers of possible answers. The main view of the app is a UIScrollView, and within that is a UILabel containing the question text (which is resized using the sizeToFit method, the reposition accordingly) and a UITableView containing the possible answers (with the data for the table rows being changed as the user moves between the questions), from which the user will choose the needed answers.
Due to the varying number of answers i need to be able to resize the table to fit with the number of rows. However, the size of the table doesn't change from the initial one i set in IB, and so either some questions are cut off because the control is not long enough, or there is extra empty space underneath the rows when there is more space than is needed.
If i wasn't using a scroll view for the wrapping of the question and answer, I could simply set the size of the control to be large enough for the maximum number of answers to fit on, but with the scroll view it allows the user to scroll through the extra padding (due to the content size of the scroll view being set dynamically per question, based on the size of the controls plus a little padding). While this doesn't break the app, it does make it look odd/shoddy.
I'm pretty sure i could set the height of the control manually, based on knowing the height for each table row and the number of rows needed, but i'm guessing there is a way to do this that i just don't know about. I don't want to have the table of answers scroll itself, as it would mean having a scrolling control within another scrolling control.
I've done a fair bit of googling and searching on this and other forums, but haven't really found anything...mainly its people wanting to resize the table cells, not the table itself.
Anyone got advice on what to try? Any comments would be appreciated.
|