Reputation:
I want to my cell return the first 20 character for my title in my cell, How can I do that ? and where ? I didn't find enough information about that, and the only way to do it is by customize my cell
or Can I set a max characters to return by string on my array ?
myCell.textLabel?.text?.characters.count < 20
Upvotes: 0
Views: 137
Reputation: 125007
I want to my cell return the first 20 character for my title in my cell
This sounds like a poor design. Tables and cells are for displaying information, not for storing it. Generally speaking, you should get data from the model or data source that the information came from in the first place. The only objects that should really be interacting with the cell are the table itself and the view controller that manages the table, and the view controller almost certainly has access to the source of the data.
How can I do that?
NSString
has methods to get parts of a string. In this case, it sounds like you want this:
myCell.textLabel?.text.substringToIndex(20)
In other words, use the substringToIndex()
method of NSString
to get the first 20 characters of the string that is the text of your label.
Upvotes: 2