Created
February 19, 2018 18:46
-
-
Save DonMag/beec6d563c607e31ca0d0caf5d3edc65 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
| // | |
| // WithAlertTableViewController.m | |
| // OCVeryTemp | |
| // | |
| // Created by Don Mag on 2/19/18. | |
| // | |
| #import "WithAlertTableViewController.h" | |
| @interface WithAlertTableViewController () | |
| @property NSMutableArray *theData; | |
| @end | |
| @implementation WithAlertTableViewController | |
| - (void)viewDidLoad { | |
| [super viewDidLoad]; | |
| // init data array with single-letter strings | |
| _theData = [NSMutableArray array]; | |
| NSString *str = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
| for (int i = 0; i < [str length]; i++) { | |
| NSString *ch = [str substringWithRange:NSMakeRange(i, 1)]; | |
| [_theData addObject:ch]; | |
| } | |
| } | |
| #pragma mark - Table view data source | |
| - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { | |
| return 1; | |
| } | |
| - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { | |
| return [_theData count]; | |
| } | |
| - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WithAlertCell" forIndexPath:indexPath]; | |
| cell.textLabel.text = [NSString stringWithFormat:@"Row: %ld - %@", (long)indexPath.row, _theData[indexPath.row]]; | |
| return cell; | |
| } | |
| - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| NSString *title = @"This is the title"; | |
| UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert]; | |
| _theData[indexPath.row] = @"Modified data"; | |
| // save | |
| [alertController addAction:[UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { | |
| // this causes a scroll jump when called in this block | |
| [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
| }]]; | |
| // cancel | |
| [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; | |
| [self presentViewController:alertController animated:YES completion:nil]; | |
| } | |
| @end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment