Extend cell height with labet text in tableview cell ios - ios7

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString * message =[[chatData objectAtIndex:indexPath.row]valueForKey:#"message"];
NSString * message_type = [[chatData objectAtIndex:indexPath.row]valueForKey:#"message_type"];
if([[[chatData objectAtIndex:indexPath.row]valueForKey:#"message_type"] isEqualToString:#"0"]){
CGSize sizeText = [self text:message sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(CGRectGetWidth([UIScreen mainScreen].bounds) - 100, 9999) withLinebreakmode:NSLineBreakByWordWrapping];
CGFloat heightOfRow = sizeText.height + 2 * 7.5f;
return heightOfRow + 50;
}
else
return 225;//message_type 1 3 4
// return self.chatTable.rowHeight;
}
pragma mark - Handling ChatLabel Width
-(CGSize)text:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)ConstSize withLinebreakmode :(NSLineBreakMode) linebreakmode
{
CGSize retsize;
if ([text respondsToSelector:#selector(boundingRectWithSize:options:attributes:context:)])
{
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = linebreakmode;
// paragraphStyle.alignment = NSTextAlignmentLeft;
NSDictionary * attributes = #{NSFontAttributeName : font,NSParagraphStyleAttributeName : paragraphStyle};
retsize = [text boundingRectWithSize:ConstSize options:NSStringDrawingUsesFontLeading
|NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
retsize.height =ceilf(retsize.height);
retsize.width =ceilf(retsize.width);
NSLog(#"%f",retsize.width);
}else{
if ([text respondsToSelector:#selector(sizeWithFont:constrainedToSize:lineBreakMode:)]){
retsize = [text sizeWithFont:font
constrainedToSize:ConstSize
lineBreakMode:linebreakmode];
retsize = [text boundingRectWithSize:ConstSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nil context:nil].size;
}
}
//[self viewWillAppear:YES];
return retsize;
}

Try this code.
1.if you use this code,you should give only top,bottom,left and right constraint for label.
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
//Here you give a minimum height of the cell size.
return 110;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}

Related

NSTextField dynimic height in NSTableView

There is a NSTextField in a NSTableView.
The height of the text in the window resizing is increased.
but Not grow the cells in a table view.
In this case, the height of table view cell to alter how do you like?
in short, When resizing the size of the text view, I want to change the size of the cell.
like this: (Mac store)
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row;
{
KFCustomCellView *cellView = [tableView makeViewWithIdentifier:#"MainCell" owner:self];
NSString *comment = [[_commentList objectAtIndex:row]valueForKey:#"COMMENT"];
[cellView.comment setStringValue:comment];
float cellheight = [comment heightForStringDrawing:comment font:[cellView.comment font] width:self.view.frame.size.width * 0.8];
if (cellheight > cellView.comment.frame.size.height)
{
return (cellheight + 65);
}
return 90;
}
Use following approach the to resize cell height according to textview content :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *DataCellId = #"DataCell";
dataCell = (Cell *)[tableView dequeueReusableCellWithIdentifier:DataCellId];
if(!dataCell)
{
dataCell = [[[Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DataCellId] autorelease];
}
dataCell.dataCellTextView.tag = indexPath.row;
dataCell.dataCellTextView.text =[yourDataArry objectAtIndex:indexPath.row];
return dataCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
#define PaddingForTableRowHeight 24
NSString *text;
if([yourDataArry count] > indexPath.row)
{
text = [yourDataArry objectAtIndex:indexPath.row];
} else {
text = #"";
}
UIFont *dataFont = [UIFont boldSystemFontOfSize:16.0f];
CGSize textSize ;
if([UICommonUtils checkIfiOS7])
{
// For iOS7
textSize = [text boundingRectWithSize:CGSizeMake("YOUR CELL WIDTH", MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:#{NSFontAttributeName:dataFont} context:nil].size;
} else {
textSize = [text sizeWithFont:dataFont constrainedToSize:CGSizeMake("YOUR CELL WIDTH" - PaddingForTableRowHeight,MAXFLOAT)];
}
float textViewHeight = MAX(kDefaultCellHeight, textSize.height+PaddingForTableRowHeight);
return textViewHeight;
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{
[self scrollToCursorForTextView:textView];
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
if([yourDataArry count] > textView.tag)
{
[yourDataArry replaceObjectAtIndex:textView.tag withObject:textView.text];
}
}
- (void)textViewDidChange:(UITextView *)textView
{
dataUpdated =YES;
if([yourDataArry count] > textView.tag)
{
[yourDataArry replaceObjectAtIndex:textView.tag withObject:textView.text];
}
[self performSelector:#selector(dataReload) withObject:nil afterDelay:0.0];
[self scrollToCursorForTextView:textView];
}
-(void)dataReload
{
[self.tbl beginUpdates];
[self.tbl endUpdates];
}
There are two methods which are used to draw a cell if you know
1-viewForTableColumn
2-objectValueForTableColumn
In the above methods,when you draw your textfield you can give the dynamic height or your row as you are giving in heightforrowatindexpath method.By doing this your cell will get the accurate height. If you have any problem in calculating dynamic height then tell me I'll post the code here for calculating it.

Resizing UITextView and UITableViewCell

I have new to objective C programming and i am currently trying to develop an iOS app. I am loading comment from the server onto the UITextView in the UITableViewCell.
This is the code that is used to load data into the UITextview.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// set the location to read the sample data
static NSString *CellIdentifier = #"CommentCell";
CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PostModel *posts;
CommentModel *comments;
if (contentTitle == nil) {
posts = _feed.posts[articleIndexPath.section];
comments = posts.comments[indexPath.section];
}
else {
posts = _feed.posts[searchResult];
comments = posts.comments[indexPath.section];
}
NSString *content = comments.content;
content = [content stringByReplacingOccurrencesOfString:#"<p>" withString:#""];
content = [content stringByReplacingOccurrencesOfString:#"</p>" withString:#""];
cell.usernameLabel.text = comments.name;
[cell.commentTextView setScrollEnabled:YES];
cell.commentTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cell.commentTextView.text = content;
[cell.commentTextView sizeToFit];
[cell.commentTextView setScrollEnabled:NO];
[cell.commentTextView setTextColor:[UIColor whiteColor]];
[cell.usernameLabel setTextColor:[UIColor whiteColor]];
// make the borders of the cell round
[cell.layer setCornerRadius:7.0f];
[cell.layer setMasksToBounds:YES];
cell.contentView.layer.borderColor = [[UIColor colorWithRed:51/255 green:56/255 blue:67/255 alpha:1] CGColor];
//make the borders of the image round
[cell.userImage.layer setMasksToBounds:YES];
[cell.userImage.layer setCornerRadius:7.0f];
return cell;
}
This is the code that i used to resize the UITableViewCell and UITextView
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"CommentCell";
CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
PostModel *posts;
CommentModel *comments;
if (contentTitle == nil) {
posts = _feed.posts[articleIndexPath.section];
comments = posts.comments[indexPath.section];
}
else {
posts = _feed.posts[searchResult];
comments = posts.comments[indexPath.section];
};
if (cell.commentTextView.textContainer.size.height >= 40) {
float height = [self heightForTextView:cell.commentTextView containingString:comments.content];
return height;
}
else {
return 79;
}
}
This is the method that i used to detect the height of the text
- (CGFloat)heightForTextView:(UITextView *)textView containingString:(NSString *)string {
float horizontalPadding = 8;
float verticalPadding = 16;
float widthOfTextView = textView.textContainer.size.width - horizontalPadding;
float height = [string sizeWithFont:textView.font constrainedToSize:CGSizeMake(widthOfTextView, 999999.0f) lineBreakMode:NSLineBreakByWordWrapping].height + verticalPadding;
return height;
}
- (CGSize)text: (NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7")) {
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
CGRect frame = [text boundingRectWithSize:size options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:attributesDictionary context:nil];
return frame.size;
}
else {
return [text sizeWithFont:font constrainedToSize:size];
}
}
It load fine when i run it initially but when i scroll down and back up, the UITextView became a vertical single line column.
Any help would be greatly appreciated!
I think the this might be the cause:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
You are using a dequeued cell's text view to determine the height of the cell. However the dequeued cell may not having any text data (or different text) in it, plus the commentView is UIViewAutoresizingFlexibleWidth, the width calculated by
float widthOfTextView = textView.textContainer.size.width - horizontalPadding;
may be very small under the scenario of scroll down and backup.

Changing height dynamic for Table Rows , CustomCell and Layout

There is a custom cell. In it there is two labels. One of them called nameLabel's height has to change dynamically. It can be 1,2 or 3 lines sometimes. But the rows are on eachother, they cross their own row lines. How can I solve this problem?
The labels and Custom Cell object's Use Autolayout option is disabled.
The label height has to change dynamic, And then the CustomCell's. And then tableRow. My head is confused. And why can't I see CustomCell's background color is changing?
Thanks
Here is my code for :
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *label = [[UILabel alloc] init];
label.numberOfLines = 0; // allows label to have as many lines as needed
label.text = [[self.dataList objectAtIndex:indexPath.row] objectForKey:#"NAME"];
CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(320, 63) lineBreakMode:NSLineBreakByWordWrapping];
CGFloat h = labelSize.height;
NSInteger x=0.0;
if (h==63.0) x=30;
if (h==42.0) x=20;
if (h==21.0) x=10;
return h+30;
}
- (UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = #"cellid";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil)
{
cell = (CustomCell*)[[[NSBundle mainBundle]
loadNibNamed:#"CustomCell" owner:nil options:nil]
lastObject];
}
// customization
NSDictionary *d = [self.dataList objectAtIndex:indexPath.row];
cell.nameLabel.text = [d objectForKey:#"NAME"];
cell.cityLabel.text = [d objectForKey:#"CODE"];
cell.indexPath = indexPath;
return cell;
}
At this link there is picture of simulator and xib of the Custom Cell to understand easy the problem:
http://compfreek.wordpress.com/2013/08/14/custom-cell-for-table-row-height-changes-dynamic/
Hear is another way try this change according to ur code it may different, but it may solve your problem.I am putting all views through code only, because it is easy for me check this out.
//in your subclassed class
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
//may be u did same i am adding the label to cell
UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectZero];
nameLabel.numberOfLines = 5; //set number of lines
nameLabel.tag = 100;
[self addSubview:nameLabel];
UILabel *otherLabel = [[UILabel alloc] initWithFrame:CGRectZero];
otherLabel.tag = 200;
[self addSubview:otherLabel];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
//do your customisation when cell is selected
}
-(void)layoutSubviews
{
//in this method i am setting the frames for label
[super layoutSubviews];
UILabel *nameLabel = (UILabel *) [self viewWithTag:100];
nameLabel.text = self.nameString;
CGSize maxSize = CGSizeMake(self.bounds.size.width / 2, MAXFLOAT);//set max height
CGSize nameSize = [self.nameString sizeWithFont:[UIFont systemFontOfSize:17]
constrainedToSize:maxSize
lineBreakMode:NSLineBreakByWordWrapping];
nameLabel.frame = CGRectMake(self.bounds.origin.x +2,self.bounds.origin.y+3, nameSize.width, nameSize.height);
UILabel *otherLabel = (UILabel *) [self viewWithTag:200];
otherLabel.frame = CGRectMake(nameLabel.frame.size.width+15,self.bounds.origin.y+3, 100, 40);
otherLabel.text = self.otherString;
}
//in your main class
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:#"CustomCell"];
if(cell == nil)
{
cell = [[[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"CustomCell"]autorelease];
}
//change it for ur need
NSString *name = #"hear is your long length name uzamaki naruto from uzamaki clan";
NSString *other = #"other name";
cell.nameString = name;
cell.otherString = other;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *name = #"hear is your long length name uzamaki naruto from uzamaki clan";
//replace it your height logic
float cellWidth = 350; // ur cell width
CGSize maxSize = CGSizeMake( cellWidth / 2, MAXFLOAT);//set max height
CGSize nameSize = [name sizeWithFont:[UIFont systemFontOfSize:17]
constrainedToSize:maxSize
lineBreakMode:NSLineBreakByWordWrapping];
return nameSize.height + 10;// for ur height
}

SDWebImage not showing randomly in UITableViewCell

Hello I have a script that downloads an image and dynamically sets the UITableView height after it finishes the download, but some images randomly do not show , the curious think is that when i change back and forth the tab the images suddenly appear . in the options argument i am passing SDWebImageRetryFailed.
Any idea would be more than welcome , thanks.
#interface NeobuggyFrontPageViewController()
{
UIImageView *adBanner;
NSArray *news ;
NSMutableData *imageData;
NSURLConnection *connection;
UIImage *neoImage;
NSString *category;
RSSItem *item;
FrontPageViewNewsCell *cell ;
CGRect newFrame;
__block CGRect descFrame;
float newWidth , newHeight;
__block float blockHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
item = [news objectAtIndex:[indexPath row]];
cell = [tableView dequeueReusableCellWithIdentifier:#"FrontPageNewsCell"];
[[cell newsTitle] setText:[item title]];
[[cell newsVideo] setAlpha:0.0];
if ([item newsImageURL]){
descFrame = [[cell newsBody] frame];
[[cell newsImage] setImageWithURL:[item newsImageURL] placeholderImage:[UIImage imageNamed:#"placeholderImage.png"] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
if (image) {
CGRect newsImageFrame = [[cell newsImage] frame];
float downImageWidth = image.size.width;
float downImageHeight = image.size.height;
float newsImageWidth = 304.00; //imageViewSize.size.width;
if (downImageWidth > newsImageWidth) {
float scaleFactor = newsImageWidth / downImageWidth;
newWidth = downImageWidth * scaleFactor;
newHeight = downImageHeight * scaleFactor;
} else {
newWidth = downImageWidth;
newHeight = downImageHeight;
}
newFrame = CGRectMake(newsImageFrame.origin.x, newsImageFrame.origin.y, newWidth, newHeight);
[[cell newsImage] setFrame:newFrame]; //asigno el nuevo frame a la imagen .
float newOriginY = newFrame.origin.y + newFrame.size.height + 10.00;
descFrame = CGRectMake(cell.newsBody.frame.origin.x,
newOriginY,
304.00,
cell.newsBody.frame.size.height);
blockHeight = newHeight;
}
NSLog(#"image %# cached ? %u", image ,cacheType);
if (error) {
NSLog(#"Error: %#",error);
}
}];
} else if([item newsVideoURL]) {
[[cell newsImage] setAlpha:0.0];
[[cell newsVideo] setAlpha:1.0];
[[cell newsVideo] loadRequest:[NSURLRequest requestWithURL:[item newsVideoURL]]];
float newOriginY = cell.newsVideo.frame.origin.y + cell.newsVideo.frame.size.height + 10.00;
descFrame = CGRectMake(cell.newsBody.frame.origin.x, newOriginY, 304, cell.newsBody.frame.size.height);
blockHeight = cell.newsVideo.frame.size.height;
}
[[cell newsImage] setNeedsDisplay];
NSString *desc = [[NSString alloc] initWithString:[item description]];
[[cell newsBody] setFrame:descFrame];
desc = [desc htmlToString:desc];
[[cell newsBody] setText:desc];
[[cell newsBody] setNumberOfLines:0];
[[cell newsBody] sizeToFit];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
cell = (FrontPageViewNewsCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
CGSize descHeight = [[[cell newsBody] text] sizeWithFont:[[cell newsBody] font] constrainedToSize:cell.newsBody.frame.size lineBreakMode:[[cell newsBody] lineBreakMode]];
CGSize titleHeight = [[[cell newsTitle] text] sizeWithFont:[[cell newsTitle] font] constrainedToSize:cell.newsTitle.frame.size lineBreakMode:[[cell newsTitle] lineBreakMode]];
newHeight = cell.newsImage.frame.size.height;
if (blockHeight == 0) {
[tableView reloadData];
} else {
float ch = titleHeight.height + blockHeight + descHeight.height + 70;
[self setCellHeight:ch];
}
return _cellHeight;
}
Partially solved although solution less than ideal. Since i only needed to show 10 cells I prevented the reuse of the UITableViewCell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
item = [news objectAtIndex:[indexPath row]];
NSString *identifier = [NSString stringWithFormat:#"Cell %d", indexPath.row];
UINib *nib = [UINib nibWithNibName:#"FrontPageViewNewsCell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:identifier];
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
// cell = [tableView dequeueReusableCellWithIdentifier:#"FrontPageNewsCell"];
still interested in finding a solution reusing cell
Thanks,

Changing the size of a UITableViewCell based on the size of a subview

How can I scale UITableViewCells based on the amount of content in them? In my cells I use three labels which represent a forum. The labels are named "alias", "date", and "comments". The third label, comments, can be any number of rows. Therefore, I need my cells to become dynamically size, depending on the amount of text in the "comments" label. Here is my code:
- (BOOL)textFieldShouldReturn:(UITextField *)pTextField
{
[self setLoadingState:YES];
[pTextField resignFirstResponder];
NSUserDefaults *userStorage = [NSUserDefaults standardUserDefaults];
NSString *alias = [self urlEncode:[userStorage objectForKey:#"alias"]];
NSString *email = [self urlEncode:[userStorage objectForKey:#"email"]];
NSString *who = [self getUniqueDeviceId];
NSString *comment = [self urlEncode:[pTextField text]];
comment = [comment stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
who = [who stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([self isBlank:comment])
{
[self setLoadingState:NO];
pTextField.text = #"";
return NO;
}
if([self isBlank:alias])
{
[self showMessagePopup:NSLocalizedString(#"MessageMustChooseAlias", nil)];
return NO;
}
[self.forumThreadDataProvider startSendPost:self.taskId : self.forumThreadId : alias : who : email : comment];
pTextField.text = #"";
return YES;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
- (UITableViewCell *)tableView:(UITableView *)pTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ForumthreadCell";
UITableViewCell *cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Feedback *item = [self.items objectAtIndex:indexPath.row];
UILabel *aliasLabel = (UILabel *)[cell viewWithTag:1];
UILabel *commentLabel = (UILabel *)[cell viewWithTag:2];
UILabel *dateLabel = (UILabel *)[cell viewWithTag:3];
[aliasLabel setText:item.alias];
[commentLabel setText:item.comment];
[dateLabel setText:[self.dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:(double)item.time]]];
commentLabel.numberOfLines = 0;
[commentLabel sizeToFit];
return cell;
}
Ive tryed already myself with the following code-example but it failed big-TIME:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell) {
UILabel *commentLabel = (UILabel *)[cell viewWithTag:2];
return commentLabel.frame.size.height;
}
else
return 30;
}
Check this tutorial for how to set dynamically set cell height,
Basically you need to use methods like this to calculate the height of Laebl,
- (CGFloat)RAD_textHeightForSystemFontOfSize:(CGFloat)size {
//Calculate the expected size based on the font and linebreak mode of the label
CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width - 50;
CGFloat maxHeight = 9999;
CGSize maximumLabelSize = CGSizeMake(maxWidth,maxHeight);
CGSize expectedLabelSize = [self sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap];
return expectedLabelSize.height;
}
Then you need to implement the heightForRowAtIndexPath method,
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *label = [self.aNote length] == 0 ? kDefaultNoteLabel : self.aNote;
CGFloat height = [label RAD_textHeightForSystemFontOfSize:kTextViewFontSize] + 20.0;
return height;
}