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];
}
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
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];
}
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
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.