ios - UITableViewCell detailTextLabel disappears when scrolling -
I am using an array of stars from which I set the detailTextLabel
initially All the subtitles are installed correctly but if I scrolls detailTextLabel
disappears
- (UITableViewCell *) tableView :. (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {UITableViewCell * cell = [tableview] dequeueReusableCellWithIdentifier: @ "personCell" forIndexPath: indexPath]; Person * person = [_persons objectAtIndex: indexPath.row]; Cell.textLabel.text = person.name; Cell.detailTextLabel.text = person.phone; // also tried setNeedsLayout, but [cell setsladeslayout] does not help; Return cell; }
I am using an iPhone 6 and iOS 8. I am also using Storyboard and setting UITableViewCell
for style subtitles
.
OK, now we have got the problem (with zero phone number text on the person) Can solve some ways.
It seems that you do not want to set the text to clear. I think this is due to the fact that it connects the cell in an odd way, pushing it with the title on top Goes but nothing under it Understandable
Therefore, you can create a custom UITableViewCell
subclass in which you can manage the layouts yourself and if this is an equal number of not keeping it out in a way and a phone Number to keep it out in a different way if it is not.
An easy way would be to use two different prototypes instead of cells.
Produce two prototype cells in the storyboard.
Type Basic
and give it a reuseIdentifier noPhoneNumberCell
with one. Type other subtitles
and re-identifiers using phoneNumberCell
.
Then you can do something like this in code ...
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { Person * person = [_persons objectAtIndex: indexPath.row]; UITableViewCell * cell; If (person.phone) {cell = [tableview decoucere ripe cell woth identifier: @ "phononumber cell" indexpath: indexpath]; Cell.detailTextLabel.text = person.phone; } Else {cell = [tableview] dequeueReusableCellWithIdentifier: @ "noPhoneNumberCell" forInexPath: indexPath]; } Cell.textLabel.text = person.name; Return cell; }
It will now create two lines of cells, one for people with a phone number and one for none.
Do not mix both of you in this way and avoid the kind of problem you are doing.
Comments
Post a Comment