Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

ios - Subtitles of UITableViewCell won't update

Today I started to get my apps ready for iOS8. I discovered that the subtitles of my UITableCells won't update within viewWillAppear. I brought that down to a minimal example:

I've got a static cell TableViewController with 2 cells (style = subtitle) One subtitle is empty the other one is set.

Interface builder screenschot

I update the subtitles like this:

- (void) viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
  [[self.without detailTextLabel] setText:@"foobar"];
  [[self.with detailTextLabel] setText:@"barfoo"];
}

While everythin works under iOS7 (and 6 and 5), iOS8 won't update the title of the first cell.

screenshot of simulator

However, when I touch the cell it will update and show the text.

Is this a simulator issue? A bug? Am I doing something wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As a temporary work around I simple introduced a blank space in the text label and programmatically where I set the label text to nil, I set it to a blank space

cell.detailTextLabel.text = @" ";

Adjust your logic accordingly to deal with a lone blank space as nil.

For me the detail text label didn't show up even though I had a string ready for it before the viewcontroller loaded. one of my many cells shows the current date in a detail text label as default whenever the view controller appears, but that didn't work either.

I think this has something to do with the fact that the iOS 8 is not able to update the text label's text if it set to nil initially.

So see to it that you introduce a blank space in your prototype cell as well, in interface builder. Surprisingly text in labels of my custom cells are working fine.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...