質問編集履歴
2
notification周りのコードを記載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -45,3 +45,119 @@
|
|
45
45
|
Cake側ではPOSTされたコメント内容をDBに格納しています。
|
46
46
|
|
47
47
|
APIを実行完了したタイミングでNotificationで通知を出し、そのタイミングでTableView.reloadData()を実行してもテーブルを再描画することができませんでした。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
【再追記】
|
54
|
+
|
55
|
+
Notification付近のコードは以下のとおりです。
|
56
|
+
|
57
|
+
(エラーハンドリング周りは参考書からそのまま引っ張ってきています…)
|
58
|
+
|
59
|
+
上記のUIButtonをタップした際に呼び出しているメソッドになります。
|
60
|
+
|
61
|
+
sendData()メソッドでAPIを叩いてDBに保存する形になります。
|
62
|
+
|
63
|
+
DBの値はviewWillAppear()内で最初にAPIを通して取得しています。
|
64
|
+
|
65
|
+
TableView.reloadData()メソッドの使い方を勘違いしていて、
|
66
|
+
|
67
|
+
この実装では新しくDBの値を取得できていない、ということでしょうか…?
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
お手数おかけして恐縮ですが、よろしくお願いします。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
```swift
|
76
|
+
|
77
|
+
func onClickSendButton(sender: UIButton) {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
var qc = PostCommentQueryCondition() // POSTする際のパラメータ
|
82
|
+
|
83
|
+
var comment: String = self.editField.text
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
qc.comment = comment
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
postCommentAPI = PostCommentAPI(condition: qc)
|
92
|
+
|
93
|
+
postCommentAPI.sendData()
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
postCommentObserver = NSNotificationCenter.defaultCenter().addObserverForName(
|
98
|
+
|
99
|
+
postCommentAPI.PostCommentAPISendCompleteNotification,
|
100
|
+
|
101
|
+
object: nil,
|
102
|
+
|
103
|
+
queue: nil,
|
104
|
+
|
105
|
+
usingBlock: {
|
106
|
+
|
107
|
+
(notification) in
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
self.editField.text = ""
|
112
|
+
|
113
|
+
self.myTableView.reloadData()
|
114
|
+
|
115
|
+
self.hideKeyBoard()
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// エラーがあればダイアログを開く
|
120
|
+
|
121
|
+
if notification.userInfo != nil {
|
122
|
+
|
123
|
+
if let userInfo = notification.userInfo as? [String: String!] {
|
124
|
+
|
125
|
+
if userInfo["error"] != nil {
|
126
|
+
|
127
|
+
let alertView = UIAlertController(
|
128
|
+
|
129
|
+
title: "通信エラー",
|
130
|
+
|
131
|
+
message: "通信エラーが発生しました",
|
132
|
+
|
133
|
+
preferredStyle: .Alert)
|
134
|
+
|
135
|
+
alertView.addAction(
|
136
|
+
|
137
|
+
UIAlertAction(title: "OK", style: .Default) {
|
138
|
+
|
139
|
+
action in return
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
)
|
144
|
+
|
145
|
+
self.presentViewController(alertView, animated: true, completion: nil)
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
})
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
```
|
1
API周りの説明について追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,15 @@
|
|
33
33
|
どなたか対処法をご存知のかた、ご教授いただけますと助かります。
|
34
34
|
|
35
35
|
よろしくお願いします。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
【追記】
|
42
|
+
|
43
|
+
APIはCakePHPで用意しており、URLを指定してAlamofireでPOSTしています。
|
44
|
+
|
45
|
+
Cake側ではPOSTされたコメント内容をDBに格納しています。
|
46
|
+
|
47
|
+
APIを実行完了したタイミングでNotificationで通知を出し、そのタイミングでTableView.reloadData()を実行してもテーブルを再描画することができませんでした。
|