-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiaryContentViewController.swift
78 lines (57 loc) · 2.46 KB
/
DiaryContentViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// DiaryContentViewController.swift
// ass2-5140
//
// Created by haofang Liu on 1/10/19.
// Copyright © 2019 haofang Liu. All rights reserved.
//
import UIKit
class DiaryContentViewController: UIViewController {
var temp : String?
var pressure : String?
var red : String?
var green : String?
var blue : String?
var date : String?
@IBOutlet weak var diaryTitle: UITextField!
@IBOutlet weak var diaryContent: UITextField!
weak var databaseController: DatabaseProtocol?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
databaseController = appDelegate.databaseController
}
@IBAction func createDiary(_ sender: Any) {
if diaryTitle.text != "" && diaryContent.text != "" {
let title = diaryTitle.text!
let content = diaryContent.text!
let _ = databaseController!.addDiary(title: title, content: content, date: date!, red: red!, green: green!, blue: blue!, temp: temp!, pressure: pressure!)
navigationController?.popViewController(animated: true)
return
}
var errorMsg = "Please ensure all fields are filled:\n"
if diaryTitle.text == "" {
errorMsg += "- Must provide a title\n"
}
if diaryContent.text == "" {
errorMsg += "- Must provide content"
}
displayMessage(title: "Not all fields filled", message: errorMsg)
}
func displayMessage(title: String, message: String) {
// Setup an alert to show user details about the Person
// UIAlertController manages an alert instance
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertAction.Style.default,handler: nil))
self.present(alertController, animated: true, completion: nil)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}