So I used this helpful tutorial a while back: http://locassa.com/animate-uitableview-cell-height-change/ and it was working perfectly in iOS6. However now, as I've been updating a few of my apps to iOS7 the code doesn't work... I have no idea why. The code checks out fine and it's logging which cell has been selected and which hasn't using an NSMutableDictionary
at first I though it just wasn't ordering the selections in the Dictionary properly but that wasn't it. I've come to the possible conclusion that it could be something that changed when Apple updated their iOS. here is my code below:
First I'm logging whether the cell is selected 'selectedIndexes' is my NSMutableDictionary
.
- (BOOL)cellIsSelected:(NSIndexPath *)indexPath {
// Return whether the cell at the specified index path is selected or not
NSNumber *selectedIndex = [selectedIndexes objectForKey:indexPath];
return selectedIndex == nil ? FALSE : [selectedIndex boolValue];
}
then in my didSelect method :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
BOOL isSelected = ![self cellIsSelected:indexPath];
if ([self cellIsSelected:indexPath]) {
//hide objects that are in expanded area of cell
}else {
//load objects as cell is selected
}
// Store cell 'selected' state keyed on indexPath
NSNumber *selectedIndex = [NSNumber numberWithBool:isSelected];
[selectedIndexes setObject:selectedIndex forKey:indexPath];
[self.tableView beginUpdates];
[self.tableView endUpdates];
So now I've setup what I want to happen when the cell is selected i've defined my desired height (kCellHeight
):
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if([self cellIsSelected:indexPath])
return kCellHeight * 7;
else
return kCellHeight;
}
This worked with no probelsm before but for some reason now some of the cells will expand and others won't... which I really don't understand because the dictionary is logging the correct indexPath along with its values, selected or not selected. Hopefully someone who's had a similar issue might be able to point me in the right direction? Thanks.