title: Making all the text show in a UITableView Cell
body: <p>I am loading an array into a UITableView and the components of the array are long.  What I want to do is customize the cells so that thier lenght will adjust to fit the text but the width will stay the same.  Right now what is happening is when the text gets too long it will just write off the cell and you will see this. </p>
  
  <p><img src="https://i.stack.imgur.com/uaUyy.jpg" alt="enter image description here"></p>
  
  <p>I would like to see the text hit the end of the cell and then start a new line. </p>
  
  <p>My code right now looks like this.</p>
  
  <pre><code>@implementation CRHCommentSection
  @synthesize observationTable; 
  
  NSArray *myArray; 
  
  
  
  - (void)viewDidLoad
  {
  
  
      myArray = [CRHViewControllerScript theArray];  
      NSLog(@"%@", myArray);
      //NSArray* paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0   inSection:1]];
     //[observationTable insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
  
     [observationTable reloadData]; 
  
  
      [super viewDidLoad];
  // Do any additional setup after loading the view.
  
  }
  
  
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      // Return the number of sections.
  
      NSLog(@" in method 1");
      return 1;
  }
  
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
   NSLog(@" in method 2");
  // Return the number of rows in the section.
  return [myArray count];
  
  
  }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath {
  
  NSLog(@" in method 3");
  
  static NSString *CellIdentifier = @"Cell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier];
  }
  
  cell.textLabel.text = [myArray objectAtIndex:indexPath.row];
  //cell.textLabel.text = @"Label"; 
  
  
  return cell;
  }
  </code></pre>
  
  <p>I also found some code that somebody else wrote for multiple lined cells but don't know how to make it automatic based on the length of my string from the array.</p>
  
  <pre><code>static NSString *CellIdentifier = @"MyCell"; 
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
   reuseIdentifier:CellIdentifier] autorelease];
  }
  cell.textLabel.text = @"Label';
  cell.detailTextLabel.text = @"Multi-Line\nText";
  cell.detailTextLabel.numberOfLines = 2;
  cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
  </code></pre>
  
  <p>They said that you will also need to return a suitable height for the multi-line cell and that a height of (44.0 + (numberOfLines - 1) * 19.0) should work fine.</p>
  
  <p>Does anyone have any ideas of how to do this? </p>
  
  <p>Thanks.</p>