Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I published a sample code at <a href="https://github.com/vikingosegundo/my-programming-examples/blob/master/ExtendingCells/Classes/FirstViewController.m" rel="nofollow">github</a></p> <p><em>edit</em><br> Your <code>tabelView:cellForRowAtIndexPath:</code> could look like this.</p> <pre><code>-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString * MyIdentifier = @"MyIdentifier"; UITableViewCell * cell = [self.table dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease]; cell.textLabel.frame = CGRectMake(0, 0, cell.textLabel.frame.size.width, cell.textLabel.frame.size.height); } id key = [[articles allKeys] objectAtIndex:indexPath.section]; cell.textLabel.text =@"TitleTitleTitle"; cell.detailTextLabel.text=@"DeatailDeatailDeatailDeatailDeatailDeatailDeatailDeatailDeatai"; //SEE MY NOTE BELOW if([indexPath isEqual:selectedIndexPath]){ cell.textLabel.numberOfLines=0; cell.detailTextLabel.numberOfLines=0; CGSize constraintSize; constraintSize.width = cell.textLabel.frame.size.width; constraintSize.height = MAXFLOAT; cell.textLabel.frame = [cell.textLabel.text sizeWithFont:cell.textLabel.font constrainedToSize:constraintSize]; constraintSize.width = cell.detailTextLabel.frame.size.width; constraintSize.height = MAXFLOAT; cell.detailTextLabel.frame = [cell.detailTextLabel.text sizeWithFont:cell.detailTextLabel.font constrainedToSize:constraintSize]; } else { cell.textLabel.numberOfLines=1; cell.detailTextLabel.numberOfLines=1; } return cell; } </code></pre> <p><strong>BUT</strong><br> You will also need the height of the cell by dynamic in <code>tableView:heightForRowAtIndexPath:</code>, so you should refactor the sizing parts into a helper methods, that writes the sizes of the 2 labels and the height of the cell to ivars, call the method from <code>tableView:heightForRowAtIndexPath:</code>, use the cell height there and the labels sizes in <code>tabelView:cellForRowAtIndexPath:</code> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload