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

質問編集履歴

1

コードを追加しました。

2019/08/14 07:46

投稿

kakakawashitax
kakakawashitax

スコア9

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,33 @@
1
+ ```ここに言語を入力
2
+
3
+ func time(name: String){
4
+ let formatter = DateFormatter()
5
+ formatter.dateFormat = "yyyy/MM/dd HH:mm,ss"
6
+ var nowTime = formatter.string(from: NSDate() as Date)//ここまでで、現在時刻の取得
7
+
8
+ list.insert(name + " " + nowTime, at: 0)
9
+
10
+ self.tableView.reloadData()
11
+
12
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
13
+ return list.count
14
+ }
15
+
16
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
17
+ let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
18
+ cell.textLabel!.text = list[indexPath.row]
19
+ return cell
20
+ }
21
+
22
+ //配列[list]の保存
23
+ UserDefaults.standard.list = list
24
+
25
+ }
1
- タイムカードのアプリをswiftで作っています。
26
+ ```タイムカードのアプリをswiftで作っています。
2
27
  「開始」「終了」のボタンがあり、そのボタンを押すと、押した瞬間の時刻が画面上のテーブルビューに羅列されていきます。
3
28
  ただ、アプリを閉じちゃうと、配列はまっさらに戻ってしまうので、そうならないよう、配列をUserDefaultsで保存し、起動時に保存したデータを、再度読み込みたいです。
4
29
 
5
30
  保存するところから詰まっています。
31
+ 上記のtime()関数で、配列を保存しちゃいたいです。
6
32
 
7
33
  よろしくお願い致します。