I'd like to know if this is possible:
- when viewing a table containing multiple comments from a post, each comment may have different lengths - so the table cells should resize vertically to accomodate more text.
Note I am looking for a different solution than posted here and elsewhere in SO, because I'd like to achieve this result without having to add code to my controller.
Using IB, my cell uses:
- style: subtitle
- mode: scale to fit
- row height: default
My "Title" label (which is the one that should expand):
- line breaks: word wrap
- lines: 0
With the above, I actually get to see the multiple lines of text, but the rows do not resize accordingly -- so the text from several rows gets overlapped.
Is it possible to have the rows resize vertically without coding this into my controller?
CommentViewController.m
#import "CommentViewController.h"
@implementation CommentViewController
@synthesize commentsArray;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return commentsArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"commentCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *comment = [commentsArray objectAtIndex:indexPath.row];
NSString *commentText = [comment objectForKey:@"comment_text"];
NSString *commentAuthor = [comment objectForKey:@"comment_author_name"];
cell.textLabel.text = commentText;
cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", commentAuthor];
return cell;
}
@end