Probably the easiest way to achieve this would be having 2 cell prototypes for:
- Not selected: with 2 UILabels; // let is be with ID:
@"NotSelectedCell"
- Selected: with all 3 UILabels; //
@"SelectedCell"
Also You need to store the indexPath
of the selected cell, so:
@implementation InformationTableViewController {
NSIndexPath* selectedCellIndexPath;
}
In your tableView delegate method tableView:cellForRowAtIndexPath:
you need to switch between NotSelectedCell
and SelectedCell
according to the indexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath isEqual:selectedCellIndexPath]) {
NSString* cellIdentifier = @"SelectedCell";
InformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell == nil) {
cell = [[InformationTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.title = // title
cell.date = // date
cell.description = // description
return cell;
}
else {
NSString* cellIdentifier = @"NotSelectedCell";
InformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell == nil) {
cell = [[InformationTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.title = // title
cell.date = // date
return cell;
}
}
Also you must save a new indexPath everytime user selects a new cell and reload the tableView:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedCellIndexPath = [indexPath copy];
[self.tableView reloadData];
}
In order to recover the scroll position of the tableView before reload, you have to do the following:
CGFloat tableViewContentHeight = self.tableView.contentSize.height;
[self.tableView reloadData];
CGFloat newTableViewContentHeight = self.tableView.contentSize.height;
self.tableView.contentOffset = CGPointMake(0, newTableViewContentHeight - tableViewContentHeight);