質問編集履歴

1

AddViewControllerのコードの追記

2020/05/09 01:10

投稿

Kaguya_4869
Kaguya_4869

スコア117

test CHANGED
File without changes
test CHANGED
@@ -265,3 +265,77 @@
265
265
 
266
266
 
267
267
  よろしくお願いします。
268
+
269
+
270
+
271
+ #追記- AddTableViewController(追加画面)
272
+
273
+
274
+
275
+ ```swift
276
+
277
+ import UIKit
278
+
279
+ import RealmSwift
280
+
281
+
282
+
283
+ class AddTableViewController: UITableViewController{
284
+
285
+
286
+
287
+ @IBOutlet weak var timeOneTextField: UITextField!
288
+
289
+ @IBOutlet weak var timeTwoTextField: UITextField!
290
+
291
+ @IBOutlet weak var subjectTextField: UITextField!
292
+
293
+ @IBOutlet weak var contentTextView: UITextView!
294
+
295
+
296
+
297
+ @IBAction func Save() {
298
+
299
+ let realm = try! Realm()
300
+
301
+ let formatter = DateFormatter()
302
+
303
+ formatter.dateFormat = "yyyy年MM月dd日"
304
+
305
+ let date = formatter.string(from: Date())
306
+
307
+ print(formatter.string(from: Date()))
308
+
309
+
310
+
311
+ try! realm.write{
312
+
313
+ let events = [Event(value: ["time1": timeOneTextField.text!,
314
+
315
+ "time2": timeTwoTextField.text!,
316
+
317
+ "subject": subjectTextField.text!,
318
+
319
+ "content": contentTextView.text!,
320
+
321
+ "date": date])]
322
+
323
+
324
+
325
+ realm.add(events)
326
+
327
+ print("書き込み中")
328
+
329
+ }
330
+
331
+ print("書き込み完了")
332
+
333
+ navigationController?.popViewController(animated: true)
334
+
335
+ }
336
+
337
+ }
338
+
339
+
340
+
341
+ ```