Created
October 20, 2015 01:04
-
-
Save Altimor/ff2bb70c23b8bd40537c to your computer and use it in GitHub Desktop.
Apple's horrible way to set up and configure table view cells (https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW15)
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
#define MAINLABEL_TAG 1 | |
#define SECONDLABEL_TAG 2 | |
#define PHOTO_TAG 3 | |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *CellIdentifier = @"ImageOnRightCell"; | |
UILabel *mainLabel, *secondLabel; | |
UIImageView *photo; | |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; | |
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; | |
mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)]; | |
mainLabel.tag = MAINLABEL_TAG; | |
mainLabel.font = [UIFont systemFontOfSize:14.0]; | |
mainLabel.textAlignment = UITextAlignmentRight; | |
mainLabel.textColor = [UIColor blackColor]; | |
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[cell.contentView addSubview:mainLabel]; | |
secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 220.0, 25.0)]; | |
secondLabel.tag = SECONDLABEL_TAG; | |
secondLabel.font = [UIFont systemFontOfSize:12.0]; | |
secondLabel.textAlignment = UITextAlignmentRight; | |
secondLabel.textColor = [UIColor darkGrayColor]; | |
secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[cell.contentView addSubview:secondLabel]; | |
photo = [[UIImageView alloc] initWithFrame:CGRectMake(225.0, 0.0, 80.0, 45.0)]; | |
photo.tag = PHOTO_TAG; | |
photo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight; | |
[cell.contentView addSubview:photo]; | |
} else { | |
mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG]; | |
secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG]; | |
photo = (UIImageView *)[cell.contentView viewWithTag:PHOTO_TAG]; | |
} | |
NSDictionary *aDict = [self.list objectAtIndex:indexPath.row]; | |
mainLabel.text = [aDict objectForKey:@"mainTitleKey"]; | |
secondLabel.text = [aDict objectForKey:@"secondaryTitleKey"]; | |
NSString *imagePath = [[NSBundle mainBundle] pathForResource:[aDict objectForKey:@"imageKey"] ofType:@"png"]; | |
UIImage *theImage = [UIImage imageWithContentsOfFile:imagePath]; | |
photo.image = theImage; | |
return cell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment