SHARE
TWEET

Untitled

a guest Nov 9th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  TableViewCell.swift
  3. //  Table View Test 2
  4. //
  5. //  Created by Dylan McDonald on 8/26/19.
  6. //  Copyright © 2019 Dylan McDonald. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11.  
  12. var tasks:[String] = []
  13. var classes:[String] = []
  14. var duedates:[String] = []
  15. var taskComplete:[String] = []
  16.  
  17. class TableViewCell: UITableViewCell, UITextFieldDelegate {
  18.    
  19.     lazy var noHomework = UserDefaults.standard.object(forKey: "syncicloud noHomework")
  20.     lazy var doneHomework = UserDefaults.standard.object(forKey: "syncicloud doneHomework")
  21.    
  22.     @objc func dismissPicker() {
  23.     }
  24.    
  25.     @IBOutlet weak var classField: UITextField!
  26.     @IBOutlet weak var taskField: UITextField!
  27.     @IBOutlet weak var dateTextField: UITextField!
  28.    
  29.    
  30.     @IBOutlet weak var doneButtonOutlet: IndexPathCellButton!
  31.    
  32.     var taskComplete = UserDefaults.standard.string(forKey: "taskComplete")
  33.     var indexPath: IndexPath?
  34.    
  35.    
  36.     @IBAction func doneDatePickerPressed(_ sender: UIBarButtonItem) {
  37.         tasks[indexPath!.row] = taskField.text!
  38.         classes[indexPath!.row] = classField.text!
  39.         duedates[indexPath!.row] = dateTextField.text!
  40.         UserDefaults.standard.set(tasks, forKey: "syncicloud taskNameData")
  41.         UserDefaults.standard.set(classes, forKey: "syncicloud classesNameData")
  42.         UserDefaults.standard.set(duedates, forKey: "syncicloud dueDatesData")
  43.         classField.resignFirstResponder()
  44.         taskField.resignFirstResponder()
  45.         dateTextField.resignFirstResponder()
  46.        
  47.     }
  48.    
  49.  
  50.    
  51.    
  52.  
  53.     func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  54.         tasks[indexPath!.row] = taskField.text!
  55.         classes[indexPath!.row] = classField.text!
  56.         duedates[indexPath!.row] = dateTextField.text!
  57.         UserDefaults.standard.set(tasks, forKey: "syncicloud taskNameData")
  58.         UserDefaults.standard.set(tasks, forKey: "syncicloud testTaskData")
  59.         UserDefaults.standard.set(classes, forKey: "syncicloud classesNameData")
  60.         UserDefaults.standard.set(duedates, forKey: "syncicloud dueDatesData")
  61.         UserDefaults.standard.synchronize()
  62.         classField.resignFirstResponder()
  63.         taskField.resignFirstResponder()
  64.         dateTextField.resignFirstResponder()
  65.        
  66.         return true
  67.     }
  68.    
  69.    
  70.    
  71.    
  72.     func viewDidLoad() {
  73.         self.classField.delegate = self
  74.         self.taskField.delegate = self
  75.         self.dateTextField.delegate = self
  76.         dateTextField.inputView = datePicker
  77.        
  78.        
  79.        
  80.     }
  81.    
  82.    
  83.    
  84.     @IBAction func stoppedAddingTask(_ sender: Any) {
  85.      
  86.        
  87.     }
  88.    
  89.    
  90.    
  91.    
  92.    
  93.     @objc func updatethemecolor(_ notification: Notification) {
  94.    
  95.         doneButtonOutlet.backgroundColor = MyVariables.setColor
  96.     }
  97.    
  98.     var testText = ["test!!"]
  99.    
  100.     override func awakeFromNib() {
  101.         super.awakeFromNib()
  102.         dateFormatter.doesRelativeDateFormatting = true
  103.         doneButtonOutlet.backgroundColor = MyVariables.setColor
  104.         NotificationCenter.default.addObserver(self, selector: #selector(updatethemecolor(_:)), name: NSNotification.Name(rawValue: "updatethemecolor"), object: nil)
  105.        
  106.         dateTextField.accessibilityLabel = "Assignment Due"
  107.         classField.accessibilityLabel = "Class"
  108.         taskField.accessibilityLabel = "Assignment"
  109.         self.classField.delegate = self
  110.         self.taskField.delegate = self
  111.         self.dateTextField.delegate = self
  112.         dateTextField.inputView = datePicker
  113.        
  114.        
  115.      
  116.        
  117.        
  118.         // date picker setup
  119.         let datePickerView:UIDatePicker = UIDatePicker()
  120.        
  121.        
  122.         // datepicker toolbar setup
  123.         let toolBar = UIToolbar()
  124.         toolBar.barStyle = UIBarStyle.default
  125.         toolBar.isTranslucent = true
  126.         let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
  127.        
  128.         let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItem.Style.done, target: self, action: #selector(doneDatePickerPressed(_:)))
  129.         // if you remove the space element, the "done" button will be left aligned
  130.         // you can add more items if you want
  131.         toolBar.setItems([space, doneButton], animated: false)
  132.         toolBar.isUserInteractionEnabled = true
  133.         toolBar.sizeToFit()
  134.        
  135.         dateTextField.inputAccessoryView = toolBar
  136.  
  137.         func doneDatePickerPressed(){
  138.            
  139.            
  140.         }
  141.     }
  142.  
  143.     override func setSelected(_ selected: Bool, animated: Bool) {
  144.         super.setSelected(selected, animated: animated)
  145.        
  146.         // Configure the view for the selected state
  147.     }
  148.  
  149.     lazy var datePicker: UIDatePicker = {
  150.        
  151.         let picker = UIDatePicker()
  152.         picker.datePickerMode = .date
  153.         picker.addTarget(self, action: #selector(datePickerChanged(_:)), for: .valueChanged)
  154.         return picker
  155.     }()
  156.    
  157.     lazy var dateFormatter: DateFormatter = {
  158.         let formatter = DateFormatter()
  159.         formatter.dateStyle = .full
  160.         formatter.timeStyle = .none
  161.        
  162.         return formatter
  163.     }()
  164.    
  165.    
  166.     @objc func datePickerChanged(_ sender: UIDatePicker) {
  167.         dateTextField.text = dateFormatter.string(from: sender.date)
  168.     }
  169. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top