Skip to content

Instantly share code, notes, and snippets.

@ninthspace
Created May 19, 2012 15:57
Show Gist options
  • Save ninthspace/2731310 to your computer and use it in GitHub Desktop.
Save ninthspace/2731310 to your computer and use it in GitHub Desktop.
Setting the content of a UITableViewCell
- (void)setWithTaskItem:(TaskItem *)task {
// set the text which displays the title of the task
NSString *text = [task title];
UILabel *titleLabel = [self taskTitleLabel];
[titleLabel setText:text];
// create a checkbox appropriately set according whether the task is completed or not
NSString *completedString = @"";
if ([task complete]) {
completedString = @"completed-";
[titleLabel setTextColor:[UIColor lightGrayColor]];
} else {
[titleLabel setTextColor:[UIColor blackColor]];
}
NSString *imageName = [[NSString alloc] initWithFormat:@"%@checkbox.png", completedString, nil];
NSString *imageHighlightedName = [[NSString alloc] initWithFormat:@"highlighted-%@checkbox.png", completedString, nil];
UIImageView *checkbox = [self checkboxImage];
[checkbox setImage:[UIImage imageNamed:imageName]];
[checkbox setHighlightedImage:[UIImage imageNamed:imageHighlightedName]];
// set the text which describes the task ID
[taskIDLabel setText:[[task uniqueID] stringValue]];
// add a recognizer for long press operations
[self addLongPressRecognizer];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment