質問するログイン新規登録

回答編集履歴

3

sy

2017/01/13 13:17

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -22,18 +22,25 @@
22
22
  )
23
23
  }
24
24
 
25
+ var isInputTextField1 = false
26
+ var isInputTextField2 = false
27
+ var isInputTextField3 = false
28
+
25
29
  // 入力値が変更された時に呼ばれるメソッド
26
30
  func didChangeNotification(notification: Notification) {
27
- dump(notification)
28
31
 
29
32
  if let textField = notification.object as? UITextField {
30
-
31
- if let text = textField.text, !text.isEmpty {
33
+ if let text = textField.text {
32
- barButtonItem.isEnabled = true
33
- } else {
34
- barButtonItem.isEnabled = false
34
+ switch textField.tag {
35
+ case CellTag.name.rawValue : isInputTextField1 = text.isEmpty ? false : true
36
+ case CellTag.category.rawValue: isInputTextField2 = text.isEmpty ? false : true
37
+ case CellTag.price.rawValue : isInputTextField3 = text.isEmpty ? false : true
38
+ default: break
39
+ }
35
40
  }
36
41
  }
42
+
43
+ barButtonItem.isEnabled = isInputTextField1 || isInputTextField2 || isInputTextField3 ? true : false
37
44
  }
38
45
 
39
46
  // 通知の解除

2

修正

2017/01/13 13:17

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  @IBOutlet weak var barButtonItem: UIBarButtonItem!
9
9
  @IBOutlet weak var textField: UITextField!
10
+ @IBOutlet weak var textField2: UITextField!
10
11
 
11
12
  override func viewDidLoad() {
12
13
  super.viewDidLoad()
@@ -23,10 +24,15 @@
23
24
 
24
25
  // 入力値が変更された時に呼ばれるメソッド
25
26
  func didChangeNotification(notification: Notification) {
27
+ dump(notification)
28
+
29
+ if let textField = notification.object as? UITextField {
30
+
26
- if let text = textField.text, !text.isEmpty {
31
+ if let text = textField.text, !text.isEmpty {
27
- barButtonItem.isEnabled = true
32
+ barButtonItem.isEnabled = true
28
- } else {
33
+ } else {
29
- barButtonItem.isEnabled = false
34
+ barButtonItem.isEnabled = false
35
+ }
30
36
  }
31
37
  }
32
38
 

1

修正

2017/01/13 00:04

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -12,6 +12,7 @@
12
12
  super.viewDidLoad()
13
13
  barButtonItem.isEnabled = false
14
14
 
15
+ // 入力値が変更された時に呼ばれる通知を登録
15
16
  NotificationCenter.default.addObserver(
16
17
  self,
17
18
  selector: #selector(self.didChangeNotification(notification:)),
@@ -20,13 +21,16 @@
20
21
  )
21
22
  }
22
23
 
24
+ // 入力値が変更された時に呼ばれるメソッド
23
25
  func didChangeNotification(notification: Notification) {
24
26
  if let text = textField.text, !text.isEmpty {
25
27
  barButtonItem.isEnabled = true
26
28
  } else {
27
29
  barButtonItem.isEnabled = false
28
- }}
30
+ }
31
+ }
29
32
 
33
+ // 通知の解除
30
34
  deinit {
31
35
  NotificationCenter.default.removeObserver(self)
32
36
  }