Dynamic cell height Problem in iPhone6 โ€‹โ€‹and iPhone6 โ€‹โ€‹plus

I am implementing a functionality in which all the labels of my cell have been changed in accordance with the text containing each label. I implemented this feature using the RayWanderlich Tutorial and it works great for iPhone 4s, 5 and 5 with iOS 8.1. as shown in the figure below, which shows a strong simulator iPhone 5s with iOS 8.1

enter image description here

while I run my application with iPhone 6 or iPhone 6, and I got unexpected behavior, as shown below, an image that shows the iPhone 6 simulator

enter image description here

and iPhone 6 plus simulator .

enter image description here

I created two custom nib files for the iPhone 4.4, 5 and 5, and a second for the iPhone 6 and 6. Since I am new to automatic layout, I set the limits the same way as with feathers. I show how custom cell files with restrictions set below the images.

IPhone snapshot 4.4, 5 and 5 sec.

enter image description here

iPhone 6 and iPhone 6 plus snapshot of custom cell file

enter image description here

I also used the following code snippet from which the cell was resized with dynamic height. The code works for iPhone iPhone 4 (for iOS 7), 4s, 5 and 5s (for iOS 7 and iOS 8 and 8.1), but not for iPhone 6 and iPhone 6 plus.

Code snippet

- (CGFloat)calculateHeightForConfiguredSizingCell_3:(MemberListTableViewCell_WithoutImage_3_iPhone *)sizingCell { sizingCell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tblView.frame), CGRectGetHeight(sizingCell.bounds)); [sizingCell setNeedsLayout]; [sizingCell layoutIfNeeded]; CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; //CGSize size = [sizingCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize withHorizontalFittingPriority:UILayoutPriorityDefaultHigh verticalFittingPriority:UILayoutPriorityDefaultHigh]; return size.height + 1.0f; // Add 1.0f for the cell separator height } 

Please give me the right solution where I am wrong. I did many things, but could not find the right way to solve this problem. Your help will be noticeable. Thanks in advanced.

+6
source share
2 answers

According to your question about cell height in iPhone6,6 Plus, you need to write below the line.

 tableView.estimatedRowHeight = 44.0 tableView.rowHeight = UITableViewAutomaticDimension 

Dynamic cell size using auto-layout link: http://www.appcoda.com/self-sizing-cells/

0
source

Is there a reason why you have two different xib for the same cell? The whole point of AutoLayout is that a single layout can be flexible enough to support all screen sizes.

When using automatic measuring cells, the key points to remember are:

  • tableView.estimatedRowHeight = <estimated_value>
  • tableView.rowHeight = UITableViewAutomaticDimension
  • Make sure your UITableViewCell subclass has an ambiguous layout, and that all elements are .contentView

Your layout looks perfect for UIStackView . I would suggest using a vertical UIStackView containing your 3 labels. Then a horizontal UIStackView containing the previous UIStackView and UIImageView . The only NSLayoutConstraints you need to create will bind an external UIStackView to all sides .contentView

For more information about UIStackViews , check out my blog post:

http://www.raizlabs.com/dev/2016/04/uistackview/

0
source

Source: https://habr.com/ru/post/980108/


All Articles