Setting a UITableViewCell accessoryType causes the the cell to disappear
| Originator: | peter.robinett | ||
| Number: | rdar://14618345 | Date Originated: | 2013-08-01 |
| Status: | Resolved | Resolved: | |
| Product: | iOS | Product Version: | 7 beta 4 |
| Classification: | Reproducible: | Always |
Summary:
Updating a UITableViewCell's accessoryType in a table view delegate's tableView:didSelectRowAtIndexPath: method causes everything in the cell but the newly set accessory to disappear: the cell background turns grey, and the textLabel and imageView disappear.
Steps to Reproduce:
1. Create a New Project, select Single View Application
2. Open Main.storyboard, add Table View to the scene
3. Connect table view's datasource and delegate to the scene's view controller
4. Make a new referencing outlet from the table view to the view controller called `tableView`
5. Open ViewController.m and add the following code:
static NSString* cellId = @"TestCell";
@implementation ViewController
- (void)viewDidLoad {
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textLabel.text = @"Test cell";
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
Expected Results:
Tapping on the single cell in the app should cause the checkmark to be displayed in the accessory view at the right of the table view cell.
Actual Results:
The checkmark is displayed, but the cell background becomes grey and everything else in the cell disappears.
Regression:
It occurs with iOS 7 beta 4. Not tested on earlier iOS 7 versions, though it did not occur in iOS 6.
Notes:
If the cell's image view is set, it will also disappear when the accessory type is set.
If an accessory view was previously set, it will also disappear. This is expected, but it should be emphasized that it seems to have no influence on the problem.
Resolved:
As it turns out, I was using dequeueReusableCellWithIdentifier:forIndexPath: incorrectly, using it in tableView:didDeselectRowAtIndexPath: when I should have been using cellForRowAtIndexPath:.
Comments
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!