Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the height of the cell if the table is loaded from 3 types of custom cells?

Tags:

ios

iphone

ipad

I have an iphone application in which I'm loading a UITableView from 3 types of custom cells. Which contains different different elements. Now i am doing it by taking the msg content of the cell and find its size and add a constant with it.But when the message is very large the content is showing in the outside part of the cell.I am doing like this `

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{  if(sarray==nil||[sarray count]==0)
    {

    }
    else
    {
          NSMutableDictionary *dicttable=[sarray objectAtIndex:indexPath.section];
          NSString *stri=[dicttable objectForKey:@"message"];
          NSString *type1=[dicttable objectForKey:@"type"];
          NSString *imagepath1=[dicttable objectForKey:@"image_path"];
         if([type1 isEqualToString:@"m"])
         {  
              if([imagepath1 isEqualToString:@"NA"])
              { 
                   UIFont *cellFont = [UIFont fontWithName:@"Helvetica Neue" size:15.0];
                   CGSize size1 = [stri sizeWithFont:cellFont constrainedToSize:CGSizeMake(300.0f, 130.0f) lineBreakMode:UILineBreakModeWordWrap];    
                   NSLog(@"%f",size1.height);
                   return size1.height+75;    
              }
              else
              {
                   UIFont *cellFont = [UIFont fontWithName:@"Helvetica Neue" size:15.0];
                   CGSize size1 = [stri sizeWithFont:cellFont constrainedToSize:CGSizeMake(300.0f, 130.0f) lineBreakMode:UILineBreakModeWordWrap];    
                   NSLog(@"%f",size1.height);

                   return size1.height+300;
              }
          }
          else
          {
               UIFont *cellFont = [UIFont fontWithName:@"Helvetica Neue" size:15.0];
               CGSize size1 = [stri sizeWithFont:cellFont constrainedToSize:CGSizeMake(300.0f, 130.0f) lineBreakMode:UILineBreakModeWordWrap];    
               NSLog(@"%f",size1.height);
               return size1.height+300;   
          }
     }
}

` Can anybody help me in finding a right approach?

like image 455
hacker Avatar asked Nov 24 '25 17:11

hacker


1 Answers

In the constrainedToSize:, you are giving it as 130. Make it as some larger value, say 1000.0f and try.

like image 150
Ilanchezhian Avatar answered Nov 27 '25 08:11

Ilanchezhian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!