Skip to content

Instantly share code, notes, and snippets.

@simondec
Created May 7, 2015 18:00
Show Gist options
  • Save simondec/000e06969bb9e3597e92 to your computer and use it in GitHub Desktop.
Save simondec/000e06969bb9e3597e92 to your computer and use it in GitHub Desktop.
@interface TestViewController : UITableViewController
@end
#import "TestViewController.h"
@interface TestViewController ()
@property (nonatomic) NSMutableDictionary *dict;
@end
@implementation TestViewController
- (void)viewDidLoad {
self.dict = [NSMutableDictionary new];
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
if (self.dict[@(indexPath.row)]) {
cell.backgroundColor = [UIColor redColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
self.dict[@(indexPath.row)] = @"YES";
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment