Skip to content

Instantly share code, notes, and snippets.

@sbrocket
Created March 12, 2011 13:40
Show Gist options
  • Select an option

  • Save sbrocket/867242 to your computer and use it in GitHub Desktop.

Select an option

Save sbrocket/867242 to your computer and use it in GitHub Desktop.
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell *cell = nil;
if ([indexPath isEqual:[tableView indexPathForSelectedRow]]) {
cell = [tableView dequeueReusableCellWithIdentifier:@"SelectedCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SelectedCell"] autorelease];
// Do any one-time setup for the cell here, like creating subviews you want to add to the cell
UIView *specialSelectedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
specialSelectedView.backgroundColor = [UIColor redColor];
specialSelectedView.center = CGPointMake(cell.bounds.size.width/2, cell.bounds.size.height/2);
specialSelectedView.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin);
specialSelectedView.tag = 1;
[cell.contentView addSubview:specialSelectedView];
[specialSelectedView release];
}
// Set the cell's data here, or do anything that needs to be done every time a cell is displayed
cell.textLabel.title = @"Selected Cell!";
// etc...
// If you want to access that view you created before, you can use viewWithTag:
UIView *specialView = [cell.contentView viewWithTag:1];
// Now you can do stuff with that view
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"StandardCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StandardCell"] autorelease];
}
cell.textLabel.title = @"";
}
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment