Created
May 13, 2014 13:36
-
-
Save zoejessica/2df4bc074691b8cf2f14 to your computer and use it in GitHub Desktop.
Calculating cell heights from auto layout prototype cells, each type of which will always be the same height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/a/16881312/2199136 | |
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { | |
NSString *cellIdentifier = [self cellIdentifierForIndexPath:indexPath]; | |
static NSMutableDictionary *heightCache; | |
if (!heightCache) | |
heightCache = [[NSMutableDictionary alloc] init]; | |
NSNumber *cachedHeight = heightCache[cellIdentifier]; | |
if (cachedHeight) | |
return cachedHeight.floatValue; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; | |
CGFloat height = cell.bounds.size.height; | |
heightCache[cellIdentifier] = @(height); | |
return height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment