3

I've been facing the problem since i decided to support IOS7, i was using heightForRowAtIndexPath to return UITableViewAutomaticDimension which is working well only with IOS8. and since UITableViewAutomaticDimensiondoesn't work with IOS7 so i have to handle it manually. but there is no such resource to help in swift about this issue.

i am using custom cell called "Card Cell" :

class CardCell: UITableViewCell {

    @IBOutlet var mainView: UIView!
    @IBOutlet weak var text1: UILabel!
    @IBOutlet weak var sharefb: UIButton!

}

so if there is anyway to handle it in heightForRowAtIndexPath manually using swift ?

AaoIi
  • 8,288
  • 6
  • 45
  • 87

2 Answers2

2

In iOS 7 you need to implement UITableViewDelegate protocol method and return your cell height.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 100.0;
}
Sergey Kuryanov
  • 6,114
  • 30
  • 52
  • i tried to do it, but the "Text Label" is not dynamic which allow 3 lines and crop the rest and this is not acceptable , so it didn't work as UITableViewAutomaticDimension in IOS8 ! – AaoIi May 03 '15 at 21:28
  • You need to return exact height in pixes it's not automatic. If you want to calculate cell height based on cell content than you need refer to this question http://stackoverflow.com/questions/20203193/calculate-cell-height-based-on-cells-text-in-ios-7 – Sergey Kuryanov May 03 '15 at 22:03
  • may i ask you to rewrite the code from objective-c to swift ? i really can't understand objective-c ! – AaoIi May 04 '15 at 05:17
0

you need to add

self.automaticallyAdjustsScrollViewInsets = false

before these two lines

tableView.estimatedRowHeight = 50
tableView.cellHeight = UITableViewCellAutomaticDimension
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
pram
  • 11
  • 2