-
Notifications
You must be signed in to change notification settings - Fork 0
/
STViewController.swift
63 lines (50 loc) · 1.64 KB
/
STViewController.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
//
// STViewController.swift
// SwiftTodo
//
// Created by Полина Абросимова on 11.02.17.
// Copyright © 2017 Полина Абросимова. All rights reserved.
//
import UIKit
import CoreData
class STViewController: UIViewController {
let coreDate = CoreData.sharedInstance
var thatText: String = ""
var isEdit: Bool = true
@IBOutlet weak var saveBtn: UIButton!
@IBOutlet weak var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
if isEdit {
textView.becomeFirstResponder()
}
else {
saveBtn.alpha = 0
textView.text = thatText as String
textView.isEditable = false
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func backBtnPressed(_ sender: Any) {
// back
self.dismiss(animated: true, completion: nil)
}
@IBAction func saveBtnPressed(_ sender: Any) {
// save data
if textView.text != "" {
let todoToSave: String = textView.text
coreDate.saveNewTodo(todo: todoToSave)
self.dismiss(animated: true, completion: nil)
}
else {
showAlertWithMessage(message: "Text field is empty!")
}
}
func showAlertWithMessage (message: String) {
let alert = UIAlertController (title: "Error", message: message, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil));
show(alert, sender: self)
}
}