使用する:
cell.textLabel.text = (readerClass.Name.length > 140 ? [readerClass.Name substringToIndex:140] : readerClass.Name);
readerClass.Name
これにより、140文字未満の場合はフルに設定され、それより長い場合は最初の140文字が設定されます。
また、UITableViewCellにUILabelがあり、...
テキストが切り捨てられると自動的に追加(省略記号)されると想定しています。そうでない場合は、省略記号を自分で追加できます。
cell.textLabel.text = (readerClass.Name.length > 140 ? [[readerClass.Name substringToIndex:137] stringByAppendingString:@"..."] : readerClass.Name);
最初の行だけを取得することについて質問したので、この質問に追加してください。
// get first line break range
NSRange rangeOfFirstLineBreak = [cell.textLabel.text rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]];
// check if first line break range was found
if (rangeOfFirstLineBreak.location == NSNotFound) {
// if it was, extract the first line only and update the cell text
cell.textLabel.text = [cell.textLabel.text substringToIndex:rangeOfFirstLineBreak.location];
}