Skip to content

Instantly share code, notes, and snippets.

@kevinvanderlugt
Last active December 11, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinvanderlugt/4590732 to your computer and use it in GitHub Desktop.
Save kevinvanderlugt/4590732 to your computer and use it in GitHub Desktop.
Set a row to uppercase on select of a tableview row
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize strings;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
strings = [NSMutableArray arrayWithObjects:@"abc",@"def",@"ghi",nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [strings count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"StringCell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
cell.textLabel.text = [strings objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[strings replaceObjectAtIndex:indexPath.row withObject:[[strings objectAtIndex:indexPath.row] uppercaseString]];
[tableView reloadData];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment