Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //
  2. // ViewController.m
  3. // Labb3TodoList
  4. //
  5. // Created by Henrik Doré on 2020-01-20.
  6. // Copyright © 2020 Henrik Doré. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "addNewTodoViewController.h"
  11.  
  12. @interface ViewController ()
  13.  
  14. @synthesize todoListArray;
  15. @synthesize todolistArrayNewFromUser;
  16.  
  17. @end
  18.  
  19. @implementation ViewController
  20.  
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23.  
  24. }
  25. -(void)viewDidAppear:(BOOL)animated{
  26. [self getUserDefaults];
  27. [_tableView reloadData];
  28. }
  29.  
  30. - (void) getUserDefaults{
  31. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  32. _todolistArrayNewFromUser = [[defaults objectForKey:@"todoarrayKey"] mutableCopy];
  33.  
  34. if(_todolistArrayNewFromUser == nil){
  35. _todolistArrayNewFromUser = [[NSMutableArray alloc] init];
  36. }
  37. }
  38.  
  39. //Denna måste finnas med tror jag. Så att den vet antal sektioner. I detta fallet 1 sektion.
  40. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  41. return 1;
  42. }
  43.  
  44. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  45. return [todolistArrayNewFromUser count];
  46. }
  47.  
  48. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  49.  
  50. UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
  51.  
  52. if (cell == nil){
  53. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  54. }
  55. cell.textLabel.text = [todolistArrayNewFromUser objectAtIndex:indexPath.row];
  56.  
  57. return cell;
  58.  
  59. }
  60. - (IBAction)newtodoBtn:(id)sender {
  61. }
  62.  
  63.  
  64. - (IBAction)updateBtn:(id)sender {
  65.  
  66. }
  67.  
  68. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement