Dynamically changing tableview table height

Swift / Objective C - an easy way to dynamically change the height of a TableView table

In my table, the cell view breaks the first row and third row, each label will be dynamic

enter image description here

+5
source share
2 answers

Add restrictions to the image (top, lead, end, height)

Do not add lower limits

enter image description here

Add restrictions for each label (top, front, back, bottom)

enter image description here

Add restrictions for the last tag (top, lead, end, bottom)

enter image description here

Set each label

Number of rows = 0

Line break mode = word warp

enter image description here

Method for Presenting Tables and Table Delegates

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("PropertyListCell", forIndexPath: indexPath) as UITableViewCell! imgProperty = viewBg.viewWithTag(111) as! RemoteImageView lblPropertyName = viewBg.viewWithTag(112) as! UILabel lblPrice = viewBg.viewWithTag(113) as! UILabel lblAddress = viewBg.viewWithTag(114) as! UILabel lblAreaPerSquare = viewBg.viewWithTag(115) as! UILabel imgProperty.imageURL = NSURL(string: "Image Url") lblPropertyName.text="Jai Maharashtra Apartment" lblPrice.text="Rs. 900 - 10000" lblAddress.text="411041,Maharashtra Sadan, Pune, Maharashtra , India" // just address changed. lblAreaPerSquare.text="500 Square Meter" cell.selectionStyle = UITableViewCellSelectionStyle.None return cell } func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return 44.0 } 

Now all tags are Dynamic

enter image description here

+23
source

Swift - 3.0

  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { var height:CGFloat = CGFloat() if indexPath.row == 0 { height = 80 } else if indexPath.row == 1 { height = self.view.frame.size.height - 80 - 44 - 64 print(height) } return height } 
0
source

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


All Articles