Last active
December 11, 2015 10:59
-
-
Save kevinvanderlugt/4590732 to your computer and use it in GitHub Desktop.
Set a row to uppercase on select of a tableview row
This file contains 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
#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