Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 06-07-2009, 10:23 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 16
Default auto expanding multiline table cells

Hi all,

I've been working on trying to get multiline auto expanding (expand to fit, or at least expand to fit a few lines) for a while and am having no luck, other than a really awful method of dynamically placing labels inside of cells which I don't like (and I can't believe that's the "correct" way to do it. Would anyone who'se figured this out care to shed some light and advice?

I'm pasting the a screenshot of what I've got so far (note the third cell is cut off and not multiline) as well as the code I've been using below.

I appreciate all of your wisdom and advice

Jeff

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [programDetails count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
		
	if (indexPath.row == 0) { // program name
		cell.font = [UIFont boldSystemFontOfSize: 12];
	} else if (indexPath.row == 1) { // program tagline
		cell.font = [UIFont systemFontOfSize: 12];
	} else { // program description
		cell.font = [UIFont systemFontOfSize: 10];
	}
	
	cell.text = [programDetails objectAtIndex:indexPath.row];
	
	return cell;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	
	self.tableView.rowHeight = 50;
	
	programDetails = [[NSMutableArray alloc] init];
	
	[self loadProgramData];
}
Attached Images
File Type: png Picture 1.png (13.4 KB, 0 views)
wickersty is offline   Reply With Quote
Old 06-08-2009, 03:11 PM   #2 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 16
Default

bumpity bump

Now I'm not surprised I havent been able to find anything on this online anywhere... seems like this is a common issue with no well known approach. We've all seen this done in various apps, so I know its possible -- it's just... how?

Quote:
Originally Posted by wickersty View Post
Hi all,

I've been working on trying to get multiline auto expanding (expand to fit, or at least expand to fit a few lines) for a while and am having no luck, other than a really awful method of dynamically placing labels inside of cells which I don't like (and I can't believe that's the "correct" way to do it. Would anyone who'se figured this out care to shed some light and advice?

I'm pasting the a screenshot of what I've got so far (note the third cell is cut off and not multiline) as well as the code I've been using below.

I appreciate all of your wisdom and advice

Jeff

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [programDetails count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
		
	if (indexPath.row == 0) { // program name
		cell.font = [UIFont boldSystemFontOfSize: 12];
	} else if (indexPath.row == 1) { // program tagline
		cell.font = [UIFont systemFontOfSize: 12];
	} else { // program description
		cell.font = [UIFont systemFontOfSize: 10];
	}
	
	cell.text = [programDetails objectAtIndex:indexPath.row];
	
	return cell;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	[super viewDidLoad];
	
	self.tableView.rowHeight = 50;
	
	programDetails = [[NSMutableArray alloc] init];
	
	[self loadProgramData];
}
wickersty is offline   Reply With Quote
Old 06-12-2009, 01:49 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 92
Default

I can't see your screenshot but if I can see it I might have some ideas
yezaev is offline   Reply With Quote
Old 06-12-2009, 07:28 PM   #4 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 16
Default

looks like attaching didnt work - so here's the screenie, embedded. Thanks!



Quote:
Originally Posted by yezaev View Post
I can't see your screenshot but if I can see it I might have some ideas
wickersty is offline   Reply With Quote
Old 06-13-2009, 05:27 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 92
Default

Quote:
Originally Posted by wickersty View Post
looks like attaching didnt work - so here's the screenie, embedded. Thanks!

So you want the last cell to be tall enough to display multiple lines of the label?
what you need to do is determine the height you need and return that value in heightForRowAtIndexPath in your table view delegate, and add a label of appropriate size and configuration to that cell's contentView
yezaev is offline   Reply With Quote
Old 06-14-2009, 09:13 PM   #6 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 16
Default

I finally nailed this and I know people are experiencing the same difficulties, so let me share what I've done:

Code:
	CGRect LabelFrame = CGRectMake(120, 33, 150, 75);
	UILabel *lblTemp;

	lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
	lblTemp.numberOfLines = 0;
	lblTemp.lineBreakMode = UILineBreakModeWordWrap;
	
	[cell.contentView addSubview:lblTemp];
This resulted in a multi-line UILabel inside my Table View Cell.

Hope this helps someone.

Jeff
wickersty is offline   Reply With Quote
Old 11-19-2009, 04:16 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
Default

The thread is not actual, but I have to thank you for your code!
I searched a while for a solution for cells with multiple lines; now I found a solution.
Sebastian is offline   Reply With Quote
Reply

Bookmarks

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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,841
Threads: 38,605
Posts: 169,509
Top Poster: smasher (2,547)
Welcome to our newest member, ashim1488
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0