Peter Warbo
Peter Warbo

Reputation: 11718

iOS - UILabel in UITableViewCell erroneously truncates text

I have a weird issue:

I'm using a UIPickerView to pick some values. When a value is picked I want to update a row in a UITableView with that value from the pickerview. So I have saved a reference to the particular cell.

So when I select a row in the pickerview I do this in the pickerview delegate method - didSelectRow...

self.pickerviewCell.textLabel.text = [self.pickerViewDataSource objectAtIndex:row];

And then I dismiss the pickerview with an animation. But for some reason after the pickerview is off the screen I see the label in the row being updated with three dots ... which would indicate that the text is too long for the label and then a second after the dots disappears and the full text of the label is displayed. The text strings are not too long, they are between 3 and 5 characters long and should fit perfectly in the textLabel of a UITableViewCell.

Anyone have a clue?

Upvotes: 1

Views: 704

Answers (2)

dentarg
dentarg

Reputation: 1764

For me, the problem was that my strings ended with \n. That worked with UITableViewCellStyleDefault, but when changing to UITableViewCellStyleSubtitle, the strings were truncated (no matter how long the string was, the three last characters where changed to ...). Removing \n from the strings fixed it.

Upvotes: 1

Peter Warbo
Peter Warbo

Reputation: 11718

Found the solution after some trial and error.

Turned out that since the cell was a custom subclass of UITableViewCell I needed to reference the instance variable to that custom subclass and not the UITableViewCell superclass.

So all I did was go from:

@property (nonatomic, strong) UITableViewCell *cell

to

@property (nonatomic, strong) MyCell *cell

And it worked out flawlessly. Pretty weird behaviour though. But it works.

EDIT:

Actually I was too quick there. It didn't work by just changing the class to my subclass. What I instead noticed worked was that if after setting the self.pickerviewCell.textLabel.text property I call [self.pickerviewCell.textLabel sizeToFit] But what is weird is that in another View Controller in my application I can do the above without needing to call - sizeToFit on the UILabel for it to display properly.

Upvotes: 0

Related Questions