Last active
August 29, 2015 14:02
-
-
Save elizaaverywilson/3a5ab72bc8d5cfe4b5dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#pragma mark Info Disclosure button | |
- (IBAction)infoDisclosureButtonClick:(id)sender { | |
UIButton *infoDisclosureButton = (UIButton*)sender; | |
// View hiearchy: InfoDisclosureButton -> Cell Content View -> Some Cell Internal View -> Cell | |
UITableViewCell *cell = (UITableViewCell*)infoDisclosureButton.superview.superview.superview; | |
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; | |
NSInteger index = indexPath.row; | |
NNItem *item = self.items[(NSUInteger)index]; | |
[item setDisclosureButtonCurrentlyOpen:!item.disclosureButtonCurrentlyOpen]; | |
if (item.disclosureButtonCurrentlyOpen) { | |
NSArray *validDescriptionUnits = [self validDescriptionUnitsFromAllDescriptionUnits:item.itemDescriptionUnits]; | |
NSString *description = item.description; | |
CGSize descriptionSize = [description sizeWithAttributes:[NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Helvetica Neue" size:17] forKey: NSFontAttributeName]]; | |
[self setupDetailsForCell:cell forValidDescriptionUnits:validDescriptionUnits descriptionString:description descriptionSize:descriptionSize]; | |
} else { | |
[self teardownDetailsForCell:cell]; | |
} | |
NSLog(@"%@", self.tableView); | |
[self.tableView reloadData]; | |
//[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; | |
} | |
static const NSUInteger NNDetailLabelsTag = 923; | |
- (void)setupDetailsForCell:(UITableViewCell*)cell forValidDescriptionUnits:(NSArray*)validDescriptionUnits descriptionString:(NSString*)descriptionString descriptionSize:(CGSize)descriptionSize { | |
[self teardownDetailsForCell:cell]; | |
NSUInteger count = 1; | |
for (NNItemDescriptionUnit *descriptionUnit in validDescriptionUnits) { | |
UILabel *label = [[UILabel alloc] init]; | |
[label setFrame:CGRectMake(5.0, (CGFloat)44.0 + count * (CGFloat)49.0, cell.frame.size.width - (CGFloat)5.0, 44.0)]; | |
NSLog(@"Label: %@", label); | |
[label setText: descriptionUnit.itemDescription]; | |
[label setTag:NNDetailLabelsTag]; | |
[cell.contentView addSubview:label]; | |
count++; | |
} | |
UILabel *description = [[UILabel alloc] init]; | |
[description setFrame:CGRectMake(5.0, (CGFloat)44.0 + count * (CGFloat)49.0, cell.frame.size.width - (CGFloat)5.0, descriptionSize.height)]; | |
[description setText:descriptionString]; | |
[description setTag:NNDetailLabelsTag]; | |
[cell.contentView addSubview:description]; | |
} | |
- (void)teardownDetailsForCell:(UITableViewCell*)cell { | |
while ([cell.contentView viewWithTag:NNDetailLabelsTag]) { | |
[[cell.contentView viewWithTag:NNDetailLabelsTag] removeFromSuperview]; | |
} | |
} | |
- (NSArray*)validDescriptionUnitsFromAllDescriptionUnits:(NSArray*)allDescriptionUnits { | |
NSMutableArray *validDescripionUnits = [NSMutableArray array]; | |
for (NNItemDescriptionUnit *descriptionUnit in allDescriptionUnits) { | |
if (descriptionUnit.isValid) { | |
[validDescripionUnits addObject:descriptionUnit]; | |
} | |
} | |
return [NSArray arrayWithArray:validDescripionUnits]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment