Skip to content

Instantly share code, notes, and snippets.

@floydpink
Created December 17, 2014 05:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save floydpink/363aac55024f5c1b8650 to your computer and use it in GitHub Desktop.
Swift UITableView set rowHeight [question on SO]
class MyController: UITableViewController, UITableViewDelegate, UITableViewDataSource {
// ...
var sizingSectionCell: SectionTableViewCell?
// ...
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
var onceToken: dispatch_once_t = 0
dispatch_once(&onceToken) {
self.sizingSectionCell = self.sectionsView.dequeueReusableCellWithIdentifier(self._sectionCellReuseIdentifier) as? SectionTableViewCell
}
var section = chapter!.sections[indexPath.row]
sizingSectionCell?.speakerLabel?.text = section.speaker
sizingSectionCell?.contentLabel.text = section.content
sizingSectionCell?.meaningLabel.text = section.meaning
sizingSectionCell?.setNeedsLayout()
sizingSectionCell?.layoutIfNeeded()
let size: CGSize = sizingSectionCell!.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
return size.height
}
@shantanubharadwaj
Copy link

Crashes everytime at the line ... self.sizingSectionCell = self.sectionsView.dequeueReusableCellWithIdentifier(self._sectionCellReuseIdentifier) as? SectionTableViewCell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment