Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-21-2009, 10:41 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
MikeSB101 is on a distinguished road
Question 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.
MikeSB101 is offline   Reply With Quote
Old 08-21-2009, 02:24 PM   #2 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
jsd is on a distinguished road
Default

UITableView doesn't respond to sizeToFit in any useful way. You'll have to adjust the tableview's frame manually.
jsd is offline   Reply With Quote
Old 08-21-2009, 02:33 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 4
MikeSB101 is on a distinguished road
Default

Quote:
Originally Posted by jsd View Post
UITableView doesn't respond to sizeToFit in any useful way. You'll have to adjust the tableview's frame manually.
Thanks for clearing that up...out of interest, is that actually documented anywhere? I've never found a reference to it not working, but it was obvious something was up with it...
MikeSB101 is offline   Reply With Quote
Old 04-07-2010, 01:21 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
mimo81 is on a distinguished road
Smile

Hey Mike, I am just learning iphone development and have exactly the same issue as you do... Have you ever found a work around for this?

Much appreciated!
mimo81 is offline   Reply With Quote
Old 05-28-2011, 02:03 PM   #5 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 1
paul.grayson is on a distinguished road
Default Try making the UITableView's frame larger

Try making the UITableView's frame larger than it needs to be before calling sizeToFit (e.g. the size of the screen would usually do). sizeToFit then shrinks the UITableView down to an appropriate size.
paul.grayson is offline   Reply With Quote
Reply

Bookmarks

Tags
sizetofit, uitableview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 316
13 members and 303 guests
chiataytuday, coolman, givensur, glenn_sayers, guusleijsten, ipodphone, jbro, mediaspree, mottdog, mtl_tech_guy, Punkjumper, vilisei, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0