title: Wrap Text in a UITableView in iOS
body: <p>I want to wrap text of the cells in the UITableView. I am using the following code but the alignment of cells isnt coming proper now how to I change the Height of the cell dynamically? I noticed that there is an inbuilt method -(CGFloat) cellHeightForRow in tableView delegate but I can I take in text and set height dynamically since I have text of variable length in my JSON data</p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *CellIdentifier = @"Cell";  
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
      if (cell == nil) {  
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];  
      }  
      [cell.textLabel sizeToFit];
      cell = [[[UITableViewCell alloc]
               initWithStyle: UITableViewCellStyleSubtitle
               reuseIdentifier: @"UITableViewCell"] autorelease];
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
  
      NSDictionary *person = [myPeople objectAtIndex:[indexPath row]]; 
  
      NSString *name = [person valueForKey:@"name"];
      cell.detailTextLabel.text = [person valueForKey:@"time"];
      return cell; 
  }
  </code></pre>
  
  <p>This is what I have tried so far :</p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
       NSDictionary *person = [myPeople objectAtIndex:[indexPath row]]; 
      NSString *cellText    =[person valueForKey:@"text"];
      UIFont *cellFont      = [UIFont fontWithName:@"Helvetica-neuve" size:21.0];
      CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
      CGSize labelSize      = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
      int buffer  = 10;
      return labelSize.height + buffer;
  }
  
  // Customize the appearance of table view cells.
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *CellIdentifier = @"Cell";  
  
      UITableViewCell *cell = [commentView dequeueReusableCellWithIdentifier:CellIdentifier];  
      if (cell == nil) 
      {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
          cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
          cell.textLabel.numberOfLines = 6;
          cell.textLabel.font          = [UIFont fontWithName:@"Helvetica-neuve" size:21.0];
          [cell.textLabel setMinimumFontSize:13.0];
          [cell.textLabel setAdjustsFontSizeToFitWidth:NO];
      } 
  
      NSDictionary *person = [myPeople objectAtIndex:[indexPath row]]; 
  
      NSString *personName = [person valueForKey:@"text"];
          cell.textLabel.text = personName;
     // cell.detailTextLabel.text = [person valueForKey:@"date"];
  
      return cell; 
  }
  </code></pre>
  
  <p>Still the output looks too clumpsy and tight</p>