I'm making an RSS parser for iPhone and iPod Touch and I need to be able to set the number of lines shown in each cell for each article. I'd like to break every 39 characters, which is the most that fits on a line at the font size that I'm using.
I'd like to take the number of characters in a string and divide it by the number of characters per line. I'd like to have an integer as an answer, rounded up where necessary.
This is what I have so far. What is wrong?
NSNumber *lines = [[NSNumber alloc] initWithInteger:[cell.textLabel.text length]/kLineLength];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setRoundingMode:NSNumberFormatterRoundUp];
[formatter setRoundingIncrement:[[[NSNumber alloc]initWithInteger:1]autorelease]];
NSNumber *roundedLines = [[NSNumber alloc]initWithInteger: [[formatter numberFromString:[lines stringValue]]integerValue]];
[cell.textLabel setNumberOfLines:[roundedLines integerValue]];
[roundedLines release];
[formatter release];
[lines release];
EDIT
I'm not after line breaks so much as knowing how many lines to give the label. So, while I'm effectively setting line-breaks, I'm not really doing that. I let the iOS figure out where to break, I just tell it how many lines to use.