Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AdityaDeshmane/2fb7d585782705cb7f8b to your computer and use it in GitHub Desktop.

Select an option

Save AdityaDeshmane/2fb7d585782705cb7f8b to your computer and use it in GitHub Desktop.
iOS: UITableView Row Automatic Height Adjustment (Self Sizing Cell)
Requirement iOS 8 and above
//1. Dyanamic table cells
//Just set following two lines in view did load
_tableView.estimatedRowHeight = someHeightConstant;//provide any value it gets set as default if no constraints are set
_tableView.rowHeight = UITableViewAutomaticDimension;
//2. Static table cells
//Handle these 2 callbacks
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return someHeightConstant;//provide any value it gets set as default if no constraints are set
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment