UITableViewCell with UITableViewCellStyleSubtitle does not recycle cells correctly

Originator:iosdeveloperzone
Number:rdar://22658505 Date Originated:11-Sep-2015 02:22 AM
Status:Closed Resolved:28-Oct-2015 10:03 PM
Product:iOS Product Version:8.2 (12D5480a), 8.3 (12F701), 8.4.1 (12H321)
Classification:UI/Usability Reproducible:Always
 
Summary:
UITableViewCells of type UITableViewCellStyleSubtitle do not display correctly if the contents of the subtitle can sometimes be nil.

Steps to Reproduce:
Run the attached project and scroll. Note that in some cases cells that claim they ought to have a subtitle do not display it. Touch one of these cells and drag (to avoid a segue) and note the subtitle appears. Rotating the device will also cause the subtitles to reappear.

Alternatively to recreate the project take the following steps:
1) Create a master/view project 
2) In the Main.storyboard choose the 'Master Scene' that contains the UITableView and set the style of the prototype cell to subtitle. 3) Edit MasterViewController.m altering the methods as shown below

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return 1000;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

	uint32_t nRows = (uint32_t)[self tableView:self.tableView  numberOfRowsInSection:0];
	if(arc4random_uniform(nRows*2) > nRows) {
		cell.textLabel.text = @"Subtitle";
		cell.detailTextLabel.text = @"This is a subtitle";
	}
	else {
		cell.textLabel.text = @"No Subtitle";
		cell.detailTextLabel.text = nil;
	}
	return cell;
}


Expected Results:
Subtitles should appear then cell.detailTextLabel.text is non-nil.

Actual Results:
It appears that when the detailTextLabel’s text is set to nil the view is removed from the view hierarchy. Setting the text to a non-nil value does not cause it to be added back until something causes a layout pass (such as a selection or rotation). 

Regression:
This is a regression from 7.1.1 (11D201). Confirmed occurring in 8.2 (12D5480a), 8.3 (12F701) and 8.4.1 (12H321).

Notes:
It’s possible to work around this by testing to see if the detail label is in the view hierarchy and adding it back in. This should not be needed.

Comments

Resolved

Confirmed resolved in iOS 9.1

By iosdeveloperzone at Oct. 29, 2015, 5:31 a.m. (reply...)

Test Code on GitHub

The code submitted to Apple can be found at https://github.com/iosdevzone/UITableViewCellSubtitleRadar

By iosdeveloperzone at Sept. 11, 2015, 9:25 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!