UITableView.automaticDimension not working












1















I've got a problem with a prototype cell (which is populated from Firebase), where the cell height is not being set correctly despite constraints being set.



I've tried setting the following:



override func viewDidLoad() {
super.viewDidLoad()

TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}


This does not work. When using UITableView.automaticDimension, the cell height defaults to 44.



However, if the cell height can be expanded if I set TableViewPVV.rowHeight explicitly to a value like 100.



NOTE: I also need to explicitly define the label's desired width or the rowHeight value specified is ignored.



ALSO NOTE: I have the following constraints set on the label: Trailing Space to Superview = 2, leading space = 2, Bottom space >= 2, Top Space >= 2.



Some screenshots as follows:





Nayem: edited to add a new image for you of what the content looks like without setting a desired width, and with the height set to 100.





import UIKit
import Firebase


class PVVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var PVVList = [PVVModel]()

@IBOutlet weak var TableViewPVV: UITableView!

override func viewDidLoad() {
super.viewDidLoad()



LoadDataFromPVV()

// TableViewPVV.rowHeight = 100
TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

return PVVList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//creating a cell using the custom class

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PVVViewControllerTableViewCell


//the PVV object
let PVV: PVVModel

//getting PVV for selected position
PVV = PVVList[indexPath.row]

//adding values to labels
cell.PVVData.text = PVV.BodyText

//returning cell
return cell
}


func LoadDataFromPVV() {


databaseReference = Database.database().reference()


let refPVV = Database.database().reference(withPath: "PVV").queryOrdered(byChild: "Status").queryEqual(toValue: "Active")

refPVV.observeSingleEvent(of: .value, with: { (snapshot) in

//if the reference have some values
if snapshot.childrenCount > 0 {

//clearing the list
self.PVVList.removeAll()


//iterating through all the values
for PVV in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
let PVVObject = PVV.value as? [String: AnyObject]
let PVVText = PVVObject?["BodyText"]


//creating PVV object with model and fetched values
let PVV = PVVModel(BodyText: PVVText as! String?)

//appending it to list
self.PVVList.append(PVV)
}

//reloading the tableview
self.TableViewPVV.reloadData()
}

})
}
}


I'm hoping to be able to dynamically adjust the height of my label (PVVData) to fit the text as captured from Firebase.










share|improve this question

























  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Bhargav Rao
    Jan 2 at 9:55
















1















I've got a problem with a prototype cell (which is populated from Firebase), where the cell height is not being set correctly despite constraints being set.



I've tried setting the following:



override func viewDidLoad() {
super.viewDidLoad()

TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}


This does not work. When using UITableView.automaticDimension, the cell height defaults to 44.



However, if the cell height can be expanded if I set TableViewPVV.rowHeight explicitly to a value like 100.



NOTE: I also need to explicitly define the label's desired width or the rowHeight value specified is ignored.



ALSO NOTE: I have the following constraints set on the label: Trailing Space to Superview = 2, leading space = 2, Bottom space >= 2, Top Space >= 2.



Some screenshots as follows:





Nayem: edited to add a new image for you of what the content looks like without setting a desired width, and with the height set to 100.





import UIKit
import Firebase


class PVVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var PVVList = [PVVModel]()

@IBOutlet weak var TableViewPVV: UITableView!

override func viewDidLoad() {
super.viewDidLoad()



LoadDataFromPVV()

// TableViewPVV.rowHeight = 100
TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

return PVVList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//creating a cell using the custom class

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PVVViewControllerTableViewCell


//the PVV object
let PVV: PVVModel

//getting PVV for selected position
PVV = PVVList[indexPath.row]

//adding values to labels
cell.PVVData.text = PVV.BodyText

//returning cell
return cell
}


func LoadDataFromPVV() {


databaseReference = Database.database().reference()


let refPVV = Database.database().reference(withPath: "PVV").queryOrdered(byChild: "Status").queryEqual(toValue: "Active")

refPVV.observeSingleEvent(of: .value, with: { (snapshot) in

//if the reference have some values
if snapshot.childrenCount > 0 {

//clearing the list
self.PVVList.removeAll()


//iterating through all the values
for PVV in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
let PVVObject = PVV.value as? [String: AnyObject]
let PVVText = PVVObject?["BodyText"]


//creating PVV object with model and fetched values
let PVV = PVVModel(BodyText: PVVText as! String?)

//appending it to list
self.PVVList.append(PVV)
}

//reloading the tableview
self.TableViewPVV.reloadData()
}

})
}
}


I'm hoping to be able to dynamically adjust the height of my label (PVVData) to fit the text as captured from Firebase.










share|improve this question

























  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Bhargav Rao
    Jan 2 at 9:55














1












1








1








I've got a problem with a prototype cell (which is populated from Firebase), where the cell height is not being set correctly despite constraints being set.



I've tried setting the following:



override func viewDidLoad() {
super.viewDidLoad()

TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}


This does not work. When using UITableView.automaticDimension, the cell height defaults to 44.



However, if the cell height can be expanded if I set TableViewPVV.rowHeight explicitly to a value like 100.



NOTE: I also need to explicitly define the label's desired width or the rowHeight value specified is ignored.



ALSO NOTE: I have the following constraints set on the label: Trailing Space to Superview = 2, leading space = 2, Bottom space >= 2, Top Space >= 2.



Some screenshots as follows:





Nayem: edited to add a new image for you of what the content looks like without setting a desired width, and with the height set to 100.





import UIKit
import Firebase


class PVVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var PVVList = [PVVModel]()

@IBOutlet weak var TableViewPVV: UITableView!

override func viewDidLoad() {
super.viewDidLoad()



LoadDataFromPVV()

// TableViewPVV.rowHeight = 100
TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

return PVVList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//creating a cell using the custom class

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PVVViewControllerTableViewCell


//the PVV object
let PVV: PVVModel

//getting PVV for selected position
PVV = PVVList[indexPath.row]

//adding values to labels
cell.PVVData.text = PVV.BodyText

//returning cell
return cell
}


func LoadDataFromPVV() {


databaseReference = Database.database().reference()


let refPVV = Database.database().reference(withPath: "PVV").queryOrdered(byChild: "Status").queryEqual(toValue: "Active")

refPVV.observeSingleEvent(of: .value, with: { (snapshot) in

//if the reference have some values
if snapshot.childrenCount > 0 {

//clearing the list
self.PVVList.removeAll()


//iterating through all the values
for PVV in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
let PVVObject = PVV.value as? [String: AnyObject]
let PVVText = PVVObject?["BodyText"]


//creating PVV object with model and fetched values
let PVV = PVVModel(BodyText: PVVText as! String?)

//appending it to list
self.PVVList.append(PVV)
}

//reloading the tableview
self.TableViewPVV.reloadData()
}

})
}
}


I'm hoping to be able to dynamically adjust the height of my label (PVVData) to fit the text as captured from Firebase.










share|improve this question
















I've got a problem with a prototype cell (which is populated from Firebase), where the cell height is not being set correctly despite constraints being set.



I've tried setting the following:



override func viewDidLoad() {
super.viewDidLoad()

TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}


This does not work. When using UITableView.automaticDimension, the cell height defaults to 44.



However, if the cell height can be expanded if I set TableViewPVV.rowHeight explicitly to a value like 100.



NOTE: I also need to explicitly define the label's desired width or the rowHeight value specified is ignored.



ALSO NOTE: I have the following constraints set on the label: Trailing Space to Superview = 2, leading space = 2, Bottom space >= 2, Top Space >= 2.



Some screenshots as follows:





Nayem: edited to add a new image for you of what the content looks like without setting a desired width, and with the height set to 100.





import UIKit
import Firebase


class PVVViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

var PVVList = [PVVModel]()

@IBOutlet weak var TableViewPVV: UITableView!

override func viewDidLoad() {
super.viewDidLoad()



LoadDataFromPVV()

// TableViewPVV.rowHeight = 100
TableViewPVV.rowHeight = UITableView.automaticDimension
TableViewPVV.estimatedRowHeight = 100

}



func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

return PVVList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//creating a cell using the custom class

let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! PVVViewControllerTableViewCell


//the PVV object
let PVV: PVVModel

//getting PVV for selected position
PVV = PVVList[indexPath.row]

//adding values to labels
cell.PVVData.text = PVV.BodyText

//returning cell
return cell
}


func LoadDataFromPVV() {


databaseReference = Database.database().reference()


let refPVV = Database.database().reference(withPath: "PVV").queryOrdered(byChild: "Status").queryEqual(toValue: "Active")

refPVV.observeSingleEvent(of: .value, with: { (snapshot) in

//if the reference have some values
if snapshot.childrenCount > 0 {

//clearing the list
self.PVVList.removeAll()


//iterating through all the values
for PVV in snapshot.children.allObjects as! [DataSnapshot] {
//getting values
let PVVObject = PVV.value as? [String: AnyObject]
let PVVText = PVVObject?["BodyText"]


//creating PVV object with model and fetched values
let PVV = PVVModel(BodyText: PVVText as! String?)

//appending it to list
self.PVVList.append(PVV)
}

//reloading the tableview
self.TableViewPVV.reloadData()
}

})
}
}


I'm hoping to be able to dynamically adjust the height of my label (PVVData) to fit the text as captured from Firebase.







ios swift uitableview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 17:37









Laurence

521519




521519










asked Jan 2 at 4:45









nm1213nm1213

448




448













  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Bhargav Rao
    Jan 2 at 9:55



















  • Comments are not for extended discussion; this conversation has been moved to chat.

    – Bhargav Rao
    Jan 2 at 9:55

















Comments are not for extended discussion; this conversation has been moved to chat.

– Bhargav Rao
Jan 2 at 9:55





Comments are not for extended discussion; this conversation has been moved to chat.

– Bhargav Rao
Jan 2 at 9:55












3 Answers
3






active

oldest

votes


















1














In most cases it's the issue of constraints .... Please make sure that your top label is top aligned with contenview and your bottom most label is aligned with bottom constraint of the contentView.



see this example



enter image description here






share|improve this answer































    0














    Please add this method in your class



    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewAutomaticDimension;
    }


    Make sure label attribute like this:



    enter image description here



    And Set proper constraint for label.






    share|improve this answer
























    • I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

      – nm1213
      Jan 2 at 5:42



















    0














    Just try the below method :



    set constraints as shown in the image below (without minimum height).



    enter image description here



    set constraints as shown in the image below (with a minimum height).



    for a minimum height you requiure a height constraint.



    enter image description here



    enter image description here



    Set number of lines to 0.



    enter image description here



     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableView.automaticDimension
    }





    share|improve this answer


























    • Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

      – nm1213
      Jan 2 at 5:46











    • No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

      – nayem
      Jan 2 at 5:47











    • @nayem i have given 40 for an example , he can give whatever minimum height he requires.

      – Shezad
      Jan 2 at 5:48













    • Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

      – nayem
      Jan 2 at 5:50











    • @nayem but the above solution works for dynamic height right?

      – Shezad
      Jan 2 at 5:53











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001293%2fuitableview-automaticdimension-not-working%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    In most cases it's the issue of constraints .... Please make sure that your top label is top aligned with contenview and your bottom most label is aligned with bottom constraint of the contentView.



    see this example



    enter image description here






    share|improve this answer




























      1














      In most cases it's the issue of constraints .... Please make sure that your top label is top aligned with contenview and your bottom most label is aligned with bottom constraint of the contentView.



      see this example



      enter image description here






      share|improve this answer


























        1












        1








        1







        In most cases it's the issue of constraints .... Please make sure that your top label is top aligned with contenview and your bottom most label is aligned with bottom constraint of the contentView.



        see this example



        enter image description here






        share|improve this answer













        In most cases it's the issue of constraints .... Please make sure that your top label is top aligned with contenview and your bottom most label is aligned with bottom constraint of the contentView.



        see this example



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 5:02









        mihir mehtamihir mehta

        12.2k15276




        12.2k15276

























            0














            Please add this method in your class



            - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
            return UITableViewAutomaticDimension;
            }


            Make sure label attribute like this:



            enter image description here



            And Set proper constraint for label.






            share|improve this answer
























            • I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

              – nm1213
              Jan 2 at 5:42
















            0














            Please add this method in your class



            - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
            return UITableViewAutomaticDimension;
            }


            Make sure label attribute like this:



            enter image description here



            And Set proper constraint for label.






            share|improve this answer
























            • I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

              – nm1213
              Jan 2 at 5:42














            0












            0








            0







            Please add this method in your class



            - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
            return UITableViewAutomaticDimension;
            }


            Make sure label attribute like this:



            enter image description here



            And Set proper constraint for label.






            share|improve this answer













            Please add this method in your class



            - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
            return UITableViewAutomaticDimension;
            }


            Make sure label attribute like this:



            enter image description here



            And Set proper constraint for label.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 5:29









            Parth PatelParth Patel

            10910




            10910













            • I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

              – nm1213
              Jan 2 at 5:42



















            • I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

              – nm1213
              Jan 2 at 5:42

















            I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

            – nm1213
            Jan 2 at 5:42





            I've tried the following before as well (swift): func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableViewAutomaticDimension } However, this did not work either. AFAIK, you don't need this method if you use: TableViewPVV.rowHeight = UITableView.automaticDimension TableViewPVV.estimatedRowHeight = 100

            – nm1213
            Jan 2 at 5:42











            0














            Just try the below method :



            set constraints as shown in the image below (without minimum height).



            enter image description here



            set constraints as shown in the image below (with a minimum height).



            for a minimum height you requiure a height constraint.



            enter image description here



            enter image description here



            Set number of lines to 0.



            enter image description here



             func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return UITableView.automaticDimension
            }





            share|improve this answer


























            • Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

              – nm1213
              Jan 2 at 5:46











            • No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

              – nayem
              Jan 2 at 5:47











            • @nayem i have given 40 for an example , he can give whatever minimum height he requires.

              – Shezad
              Jan 2 at 5:48













            • Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

              – nayem
              Jan 2 at 5:50











            • @nayem but the above solution works for dynamic height right?

              – Shezad
              Jan 2 at 5:53
















            0














            Just try the below method :



            set constraints as shown in the image below (without minimum height).



            enter image description here



            set constraints as shown in the image below (with a minimum height).



            for a minimum height you requiure a height constraint.



            enter image description here



            enter image description here



            Set number of lines to 0.



            enter image description here



             func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return UITableView.automaticDimension
            }





            share|improve this answer


























            • Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

              – nm1213
              Jan 2 at 5:46











            • No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

              – nayem
              Jan 2 at 5:47











            • @nayem i have given 40 for an example , he can give whatever minimum height he requires.

              – Shezad
              Jan 2 at 5:48













            • Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

              – nayem
              Jan 2 at 5:50











            • @nayem but the above solution works for dynamic height right?

              – Shezad
              Jan 2 at 5:53














            0












            0








            0







            Just try the below method :



            set constraints as shown in the image below (without minimum height).



            enter image description here



            set constraints as shown in the image below (with a minimum height).



            for a minimum height you requiure a height constraint.



            enter image description here



            enter image description here



            Set number of lines to 0.



            enter image description here



             func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return UITableView.automaticDimension
            }





            share|improve this answer















            Just try the below method :



            set constraints as shown in the image below (without minimum height).



            enter image description here



            set constraints as shown in the image below (with a minimum height).



            for a minimum height you requiure a height constraint.



            enter image description here



            enter image description here



            Set number of lines to 0.



            enter image description here



             func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
            return UITableView.automaticDimension
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 2 at 6:09

























            answered Jan 2 at 5:42









            ShezadShezad

            588513




            588513













            • Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

              – nm1213
              Jan 2 at 5:46











            • No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

              – nayem
              Jan 2 at 5:47











            • @nayem i have given 40 for an example , he can give whatever minimum height he requires.

              – Shezad
              Jan 2 at 5:48













            • Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

              – nayem
              Jan 2 at 5:50











            • @nayem but the above solution works for dynamic height right?

              – Shezad
              Jan 2 at 5:53



















            • Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

              – nm1213
              Jan 2 at 5:46











            • No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

              – nayem
              Jan 2 at 5:47











            • @nayem i have given 40 for an example , he can give whatever minimum height he requires.

              – Shezad
              Jan 2 at 5:48













            • Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

              – nayem
              Jan 2 at 5:50











            • @nayem but the above solution works for dynamic height right?

              – Shezad
              Jan 2 at 5:53

















            Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

            – nm1213
            Jan 2 at 5:46





            Hi Shezad, I've tried adding a height constraint >= xx, and setting the number of lines to 0. However, does not work. It's really confusing as I've looked through various solutions for days, without luck.

            – nm1213
            Jan 2 at 5:46













            No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

            – nayem
            Jan 2 at 5:47





            No. Don't suggest anything by setting explicit height. It will not help achieve automatic height. Instead height will be minimum 40 or other greater value. What if the data only fills one line and the cell size should not necessarily be >=40?

            – nayem
            Jan 2 at 5:47













            @nayem i have given 40 for an example , he can give whatever minimum height he requires.

            – Shezad
            Jan 2 at 5:48







            @nayem i have given 40 for an example , he can give whatever minimum height he requires.

            – Shezad
            Jan 2 at 5:48















            Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

            – nayem
            Jan 2 at 5:50





            Nope. His requirement doesn't say he wants to have a minimum height of whatever the value of any cell. He actually needs the dynamic height. And your solution is contradictory with this.

            – nayem
            Jan 2 at 5:50













            @nayem but the above solution works for dynamic height right?

            – Shezad
            Jan 2 at 5:53





            @nayem but the above solution works for dynamic height right?

            – Shezad
            Jan 2 at 5:53


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001293%2fuitableview-automaticdimension-not-working%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory