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 10-23-2009, 03:42 PM   #1 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2009
Location: California
Posts: 40
dougdrury is on a distinguished road
Default Easy Variable Height Table Cells

I was trying to find a clean way to change the cell height based on a large variable length label I have in a custom cell. I found this and it worked like a charm.

Apple - Support - Discussions - UITableView variable row height ...

Note sponnos post (second from the bottom):
Code:
- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath
{
    // Use the method that you would have created above to get the cell.
    // Any other method seems to result in infinite recursion like you said.
    TweetCell *cell = (TweetCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
	
	NSString *text = cell.textView.text; //[[menuList objectAtIndex:indexPath.row] objectForKey:@"status"];
	CGFloat height = [text sizeWithFont:cell.textView.font constrainedToSize:CGSizeMake(240,70) lineBreakMode:UILineBreakModeWordWrap].height;
	//return MAX(height, MinHeight);
	
	return height+30; 
}
dougdrury is offline   Reply With Quote
Old 09-17-2010, 01:46 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 3
sparshme5 is on a distinguished road
Smile Its really usefull for me

hey thanks a lot for this great idea..we can also implement this by another way just pasting the code..


- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath
{

NSString *text = [[videoCommentArray objectAtIndex:indexPath.row]getVideoComment];
CGFloat height = [text sizeWithFont:[UIFont systemFontOfSize:10] constrainedToSize:CGSizeMake(240,300) lineBreakMode:UILineBreakModeWordWrap].height;


return height+60;
}

I had done it for custom cell only and getVideoComment is the method from where i got a string.
sparshme5 is offline   Reply With Quote
Reply

Bookmarks

Tags
dynamic height, uitablecell, 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: 337
9 members and 328 guests
alexP, ClerurcifeDer, givensur, glenn_sayers, guusleijsten, ipodphone, Punkjumper, whitey99, yys
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:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0