I’m using a UITableView with cell style of UITableViewCellStyleValue1.
I’m want to have multiple lines in the detailTextLabel, is that possible? Or do I have to make a custom cell?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can set
cell.detailTextLabel.numberOfLines = 2to get 2 lines in there. However, I doubt UITableViewCell will lay out the labels as you expect in that case. You may want to subclass UITableViewCell and override-layoutSubviewsto position the labels how you want. You can call[super layoutSubviews]and then just tweak the positions of the labels. You’ll probably want to use-[NSString sizeWithFont:constrainedToSize:lineBreakMode:]to calculate the correct size for the detail text label.Alternatively, instead of subclassing UITableViewCell, you could try doing the tweaks in
-tableView:willDisplayCell:forRowAtIndexPath:, though if the cell ever decides it needs to re-layout, then your tweaks will be erased. I recommend you go with the subclassing approach.Edit: BTW, with the subclass approach, all you have to do is change
[UITableViewCell alloc]to[MyTableViewCellSubclass alloc]. Since you’re not introducing new methods or properties, the variable can still remain typed as a UITableViewCell and you won’t have to change any other code.