Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // tableViewLabb
  4. //
  5. // Created by Victor on 2020-01-23.
  6. // Copyright © 2020 Victor. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10.  
  11. @interface ViewController () <UIAlertViewDelegate>
  12.  
  13. @property (nonatomic) NSMutableArray* items;
  14. @property (strong, nonatomic) IBOutlet UITableView *tableView;
  15.  
  16. @end
  17.  
  18. @implementation ViewController
  19.  
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22.  
  23. // Do any additional setup after loading the view.
  24. self.navigationItem.title = @"To-Do list";
  25. self.tableView.delegate = self;
  26. self.tableView.dataSource = self;
  27. self.items = [[NSMutableArray alloc]init];
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  35. return 1;
  36. }
  37. - (IBAction)addTodo:(id)sender {
  38.  
  39. UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Gör" message: @"Vad behöver du göra?" preferredStyle:UIAlertControllerStyleAlert];
  40.  
  41. [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  42. textField.placeholder = @"Vad vill du göra då?";
  43. textField.textColor = [UIColor blackColor];
  44. textField.clearButtonMode = UITextFieldViewModeWhileEditing;
  45. textField.borderStyle = UITextBorderStyleRoundedRect;
  46. }];
  47.  
  48. //Button for adding the new TODO
  49. [alertController addAction:[UIAlertAction actionWithTitle:@"Okay?" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  50.  
  51. NSArray *textfields = alertController.textFields;
  52. UITextField *todo = textfields[0];
  53. [self.items addObject:todo];
  54.  
  55. [self.tableView reloadData];
  56. NSLog(@"%@", todo.text);
  57. NSLog(@"%@", self.items);
  58.  
  59. }]];
  60.  
  61. //Button for cancelling
  62. [alertController addAction:[UIAlertAction actionWithTitle:@"Avbryt" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}]];
  63.  
  64. [self presentViewController:alertController animated:YES completion:nil];
  65. }
  66.  
  67. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  68. return self.items.count;
  69. }
  70.  
  71. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  72. static NSString *CellIdentifier = @"TodoItemRow";
  73. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  74.  
  75. NSDictionary* item = self.items [indexPath.row];
  76.  
  77. cell.textLabel.text = [NSString stringWithFormat:@"%@", item.allValues];
  78.  
  79.  
  80.  
  81. return cell;
  82. }
  83.  
  84.  
  85.  
  86.  
  87. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement