Created
March 12, 2011 13:40
-
-
Save sbrocket/867243 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
| - (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.contentView.bounds.size.width/2, cell.contentView.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