回答編集履歴
3
sy
test
CHANGED
@@ -46,29 +46,43 @@
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
+
var isInputTextField1 = false
|
50
|
+
|
51
|
+
var isInputTextField2 = false
|
52
|
+
|
53
|
+
var isInputTextField3 = false
|
54
|
+
|
55
|
+
|
56
|
+
|
49
57
|
// 入力値が変更された時に呼ばれるメソッド
|
50
58
|
|
51
59
|
func didChangeNotification(notification: Notification) {
|
52
|
-
|
53
|
-
dump(notification)
|
54
60
|
|
55
61
|
|
56
62
|
|
57
63
|
if let textField = notification.object as? UITextField {
|
58
64
|
|
59
|
-
|
65
|
+
if let text = textField.text {
|
60
66
|
|
61
|
-
|
67
|
+
switch textField.tag {
|
62
68
|
|
63
|
-
|
69
|
+
case CellTag.name.rawValue : isInputTextField1 = text.isEmpty ? false : true
|
64
70
|
|
65
|
-
|
71
|
+
case CellTag.category.rawValue: isInputTextField2 = text.isEmpty ? false : true
|
66
72
|
|
67
|
-
|
73
|
+
case CellTag.price.rawValue : isInputTextField3 = text.isEmpty ? false : true
|
74
|
+
|
75
|
+
default: break
|
76
|
+
|
77
|
+
}
|
68
78
|
|
69
79
|
}
|
70
80
|
|
71
81
|
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
barButtonItem.isEnabled = isInputTextField1 || isInputTextField2 || isInputTextField3 ? true : false
|
72
86
|
|
73
87
|
}
|
74
88
|
|
2
修正
test
CHANGED
@@ -15,6 +15,8 @@
|
|
15
15
|
@IBOutlet weak var barButtonItem: UIBarButtonItem!
|
16
16
|
|
17
17
|
@IBOutlet weak var textField: UITextField!
|
18
|
+
|
19
|
+
@IBOutlet weak var textField2: UITextField!
|
18
20
|
|
19
21
|
|
20
22
|
|
@@ -48,13 +50,23 @@
|
|
48
50
|
|
49
51
|
func didChangeNotification(notification: Notification) {
|
50
52
|
|
51
|
-
if
|
53
|
+
dump(notification)
|
52
54
|
|
53
|
-
|
55
|
+
|
54
56
|
|
55
|
-
|
57
|
+
if let textField = notification.object as? UITextField {
|
56
58
|
|
59
|
+
|
60
|
+
|
61
|
+
if let text = textField.text, !text.isEmpty {
|
62
|
+
|
63
|
+
barButtonItem.isEnabled = true
|
64
|
+
|
65
|
+
} else {
|
66
|
+
|
57
|
-
barButtonItem.isEnabled = false
|
67
|
+
barButtonItem.isEnabled = false
|
68
|
+
|
69
|
+
}
|
58
70
|
|
59
71
|
}
|
60
72
|
|
1
修正
test
CHANGED
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
// 入力値が変更された時に呼ばれる通知を登録
|
30
|
+
|
29
31
|
NotificationCenter.default.addObserver(
|
30
32
|
|
31
33
|
self,
|
@@ -42,6 +44,8 @@
|
|
42
44
|
|
43
45
|
|
44
46
|
|
47
|
+
// 入力値が変更された時に呼ばれるメソッド
|
48
|
+
|
45
49
|
func didChangeNotification(notification: Notification) {
|
46
50
|
|
47
51
|
if let text = textField.text, !text.isEmpty {
|
@@ -52,9 +56,13 @@
|
|
52
56
|
|
53
57
|
barButtonItem.isEnabled = false
|
54
58
|
|
55
|
-
}
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
56
62
|
|
57
63
|
|
64
|
+
|
65
|
+
// 通知の解除
|
58
66
|
|
59
67
|
deinit {
|
60
68
|
|