Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // tableViewLabb
- //
- // Created by Victor on 2020-01-23.
- // Copyright © 2020 Victor. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController () <UIAlertViewDelegate>
- @property (nonatomic) NSMutableArray* items;
- @property (strong, nonatomic) IBOutlet UITableView *tableView;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.navigationItem.title = @"To-Do list";
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- self.items = [[NSMutableArray alloc]init];
- }
- -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (IBAction)addTodo:(id)sender {
- UIAlertController * alertController = [UIAlertController alertControllerWithTitle: @"Gör" message: @"Vad behöver du göra?" preferredStyle:UIAlertControllerStyleAlert];
- [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
- textField.placeholder = @"Vad vill du göra då?";
- textField.textColor = [UIColor blackColor];
- textField.clearButtonMode = UITextFieldViewModeWhileEditing;
- textField.borderStyle = UITextBorderStyleRoundedRect;
- }];
- //Button for adding the new TODO
- [alertController addAction:[UIAlertAction actionWithTitle:@"Okay?" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
- NSArray *textfields = alertController.textFields;
- UITextField *todo = textfields[0];
- [self.items addObject:todo];
- [self.tableView reloadData];
- NSLog(@"%@", todo.text);
- NSLog(@"%@", self.items);
- }]];
- //Button for cancelling
- [alertController addAction:[UIAlertAction actionWithTitle:@"Avbryt" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}]];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
- return self.items.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *CellIdentifier = @"TodoItemRow";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary* item = self.items [indexPath.row];
- cell.textLabel.text = [NSString stringWithFormat:@"%@", item.allValues];
- return cell;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement