I’m developing an iOS 4 application with latest SDK and XCode 4.2.
I use a web service to retrieve some text data. I don’t know its length so I will need to split that strings to fit inside a custom UITableViewCell.
This custom UITableViewCell will have an UILabel. And this label will be filled up with the text retrieved from web service.
The text will be country names: Spain, France, USA, Italy, etc. I will process this names to append them to a unique string. I will do it this way: “Spain – France – USA – …”.
One of my problems was that this line could be so long, and I need to split it into lines to fits UILabel width. I have solve this problem, checking every time I add a ‘ – ‘ if the string will get bigger than UILabel width. So, I will have a string like this: “Spain – France\nUSA – …”.
Ok. Now, I have a string with \n that will fit inside UILabel. So, I will need to modify UITableViewCell height to fits with UILabel height.
But, when I use [NSString sizeWithFont:[UIFont systemFontOfSize:kFontSize]]; I’m not getting the real height, I’m always getting 21.0f.
I’ve found this tutorial about UITableView Dynamic Height, but I don’t know how to use it with my code.
In a nutshell, I need to append ‘ – ‘ character to country names, but it there is a return carried (because the string will be rendered in another line by UILabel), I don’t have to append ‘ – ‘. And, when I get this string, I will have to resize custom UITableViewCell to UILabel height.
Any clue?
Is that something you are looking for?
Hope it helps