JohnJLilley
JohnJLilley

Reputation: 173

Resizing UITableViewCell height

I'm having an extremely difficult time resizing the .rowHeight of the cells in my .toDoListTable. The strings received from a UITextfield are being cut-off at the end of each row. I did not add a label when setting up a prototype cell since my strings are appended from a UITextField. My code is as follows:

override func viewDidLoad() {
    super.viewDidLoad()


        toDoListTable.estimatedRowHeight = 45.0

        toDoListTable.rowHeight = UITableViewAutomaticDimension


    }

}

Yet, I am still getting my text cut-off. Any suggestions? Also, is my code in the right spot?

I'm looking to have my content inside adapt to the amount of text provided from the UITextField.

EDIT: Solved problem by adding cell.textLabel?.numberOfLines = 0.

Upvotes: 1

Views: 570

Answers (3)

JohnJLilley
JohnJLilley

Reputation: 173

I know I'm late but I wanted to correctly answer my own question.

I simply added: cell.textLabel?.numberOfLines = 0 to the cellForRowAtIndexPath function to allow for multiple lines of unrestricted text.

Upvotes: 1

navroz
navroz

Reputation: 402

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
    return 30 // height you want to set.
}

Upvotes: 3

Dejan Skledar
Dejan Skledar

Reputation: 11435

Use this to set the height for the rows:

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
    {
         return 50 //your height
    }

Documentation:

https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html

Upvotes: 3

Related Questions