Independently calibrated cells (dynamic height) in iOS 8 - Perhaps without a custom UITableViewCell?

Is it possible to customize UITableViewCell in iOS 8 without creating a custom UITableViewCell?

I thought the standard types of UITableViewCell (UITableViewCellStyleDefault, UITableViewCellStyleSubtitle, UITableViewCellStyleValue1, UITableViewCellStyleValue2) built auto layout constraints. This is confirmed by the fact that the restrictions for non-standard cells cannot be changed in the Storyboard.

But when I use a non-standard cell of type UITableViewCellStyleValue1, configure it in the Storyboard, set the numberOfRows parameter for textLabel and detailTextLabel to 0 and set the viewDidLoad code as shown below, only the cell textLabel is taken into account in cell height automation. If the detailTextLabel ends up being displayed on more lines than textLabel, the text for the detailTextLabel spills over the top and bottom edges of the cell. Again, the cell resizes correctly for textLabel, but it seems to ignore detailTextLabel in the resizing process.

The main thing I need to know is I need to create a custom cell even for rows that can use a standard cell if I want to support dynamic text and self-size correctly?

- (void)viewDidLoad { [super viewDidLoad]; [self.tableView setEstimatedRowHeight:DEFAULT_ROW_HEIGHT]; [self.tableView setRowHeight:UITableViewAutomaticDimension]; } 
+8
uitableview autolayout ios8
source share
1 answer

I just tried this in iOS 10 / Xcode 8 (the same results in iOS 9 / Xcode 7) with different cell types and it looks like ONLY for textLabel, not for detailTextLabel.

(basically repeating the problem that the OP mentioned)

ViewController code that alternately sets the text for detailTextLabel and textLabel.

 class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() tableView.estimatedRowHeight = 44 tableView.rowHeight = UITableViewAutomaticDimension } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) if indexPath.row % 2 == 0 { cell.textLabel?.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." cell.detailTextLabel?.text = "<- textLabel" } else { cell.textLabel?.text = "detailTextLabel ->" cell.detailTextLabel?.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." } return cell } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } } 

Make sure that the textLabel and textDetailLabel properties are set to 0, and here are the results.

Main cell enter image description here

Right detail cell enter image description here

Left detail enter image description here

Subtitle cell enter image description here

I will report this as an error.

+3
source share

All Articles