0

I have created UITableView with default cell.imagview, cell.textLabel and cell.detailTextLabel.text.
I want to set cell dynamic according to content. I am able to set it dynamic only for either TextLabel or detailTextLabel. But to for both at same time.

Is there any way to do that?

D4ttatraya
  • 3,344
  • 1
  • 28
  • 50
New iOS Dev
  • 1,937
  • 7
  • 33
  • 67
  • create custom cell class of type UITableViewCell. – Tushar Sharma Jun 05 '17 at 12:11
  • is this possible without using custom cell? – New iOS Dev Jun 05 '17 at 12:13
  • @ sss i am not getting your question correctly do you want height of cell to be dynamic according to label text?If yes read this tutorial https://www.raywenderlich.com/129059/self-sizing-table-view-cells – Tushar Sharma Jun 05 '17 at 12:15
  • 1
    you have to set Constraints for both labels and and then set estimateRowheight and Row height in viewdidload or Just create Custom cell – Gurinder Batth Jun 05 '17 at 12:15
  • Try this https://stackoverflow.com/a/43556505/3236890 , – dip Jun 05 '17 at 12:35
  • yes I want dynamic height according to content in both TextLabel and detailTextLabel..which is not custom so I can no t set constraint....tableview is programatic – New iOS Dev Jun 05 '17 at 12:41
  • The built-in cell types have labels set to 1 line only, so in order to use dynamic height based on content in the labels requires you to write code to "customize" those elements - so you are, in essence, using a custom cell already. Why are you opposed to that? – DonMag Jun 05 '17 at 14:00

1 Answers1

0

@sss You need to return height of every cell in datasource method heightForCell at index path. so You need to calculate the height of the cell in that datasource method for every index path.

Raj Aggrawal
  • 761
  • 1
  • 6
  • 21