質問編集履歴
4
改善しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
``````ここに言語を入力
|
2
|
+
```
|
2
|
-
|
3
|
+
// ViewController.swift
|
3
4
|
// MyOkashi
|
4
5
|
//
|
5
6
|
// Created by kamiyamajota on 2021/03/03.
|
6
7
|
//
|
7
8
|
|
8
9
|
import UIKit
|
10
|
+
import SafariServices
|
9
11
|
|
10
|
-
class ViewController: UIViewController
|
12
|
+
class ViewController: UIViewController,UISearchBarDelegate,UITableViewDataSource,UITableViewDelegate,SFSafariViewControllerDelegate {
|
11
13
|
|
12
|
-
|
14
|
+
override func viewDidLoad() {
|
13
15
|
super.viewDidLoad()
|
14
16
|
// Do any additional setup after loading the view.
|
15
|
-
// Search
|
17
|
+
// Search Ba//rのdelegate通知を設定
|
16
18
|
searchText.delegate = self
|
17
19
|
// 入力のヒントとなる、プレースホルダーを設定
|
18
20
|
searchText.placeholder = "お菓子の名前を入力してください"
|
19
|
-
// Table Viewの
|
21
|
+
// Table ViewのdataSourceを設定
|
20
22
|
tableView.dataSource = self
|
21
|
-
|
23
|
+
//Table Viewのdelegateを設定
|
24
|
+
tableView.delegate = self
|
22
25
|
}
|
23
26
|
|
24
27
|
|
@@ -108,6 +111,7 @@
|
|
108
111
|
}
|
109
112
|
// Table Viewを更新する
|
110
113
|
self.tableView.reloadData()
|
114
|
+
|
111
115
|
if let okashidbg = self.okashiList.first {
|
112
116
|
print ("-----------------")
|
113
117
|
print("okashiList[0] = (okashidbg)")
|
@@ -127,14 +131,13 @@
|
|
127
131
|
// お菓子リストの総数
|
128
132
|
return okashiList.count
|
129
133
|
}
|
130
|
-
|
131
134
|
// Cellの値を返すdatasourceメゾット。必ず記?する必要があります
|
132
|
-
func
|
135
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
133
136
|
// 今回表示を行う、Cellオブジェクト(1行)を取得する
|
134
137
|
let cell = tableView.dequeueReusableCell(withIdentifier: "okashiCell", for: indexPath)
|
135
138
|
// お菓子のタイトル設定
|
136
139
|
cell.textLabel?.text = okashiList[indexPath.row].name
|
137
|
-
|
140
|
+
// お菓子の画像検索を取得
|
138
141
|
if let imageData = try? Data(contentsOf: okashiList[indexPath.row].image) {
|
139
142
|
// 正常に取得出来た場合は、UIImageで画像オブジェストを生成して、Cellにお菓子画像を設定
|
140
143
|
cell.imageView?.image = UIImage(data: imageData)
|
@@ -142,10 +145,35 @@
|
|
142
145
|
}
|
143
146
|
// 設定済みのCellオブジェクトを画像に反映
|
144
147
|
return cell
|
148
|
+
}
|
145
149
|
|
150
|
+
// Cellが選択された際に呼び出されるdelegateメソッド
|
151
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
152
|
+
// ハイライト解除
|
153
|
+
tableView.deselectRow(at: indexPath, animated: true)
|
154
|
+
|
155
|
+
// SFSafaruViewを開く
|
156
|
+
let safariViewController = SFSafariViewController(url: okashiList[indexPath.row].link)
|
157
|
+
|
158
|
+
//delegateの通知先を自分自身
|
159
|
+
safariViewController.delegate = self
|
160
|
+
|
161
|
+
//SafariViewが開かれる
|
162
|
+
present(safariViewController,animated: true,completion: nil)
|
146
163
|
}
|
164
|
+
|
165
|
+
// SafariViewが閉じられたときに呼ばれるdelegateメソッド
|
166
|
+
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
|
167
|
+
|
168
|
+
// SafariViewを閉じる
|
169
|
+
dismiss(animated: true, completion: nil)
|
170
|
+
}
|
147
171
|
}
|
148
172
|
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
149
177
|
```
|
150
178
|
```エラーコード
|
151
179
|
Type 'ViewController' does not conform to protocol 'UITableViewDataSource'
|
3
改善しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
// ViewController.swift
|
1
|
+
``````ここに言語を入力
|
2
|
+
```// ViewController.swift
|
3
3
|
// MyOkashi
|
4
4
|
//
|
5
5
|
// Created by kamiyamajota on 2021/03/03.
|
@@ -146,4 +146,7 @@
|
|
146
146
|
}
|
147
147
|
}
|
148
148
|
|
149
|
-
```
|
149
|
+
```
|
150
|
+
```エラーコード
|
151
|
+
Type 'ViewController' does not conform to protocol 'UITableViewDataSource'
|
152
|
+
```![イメージ説明]
|
2
書籍の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
](4df38266afa79b4e7d0ecf214224bdc1.png)](4df38266afa79b4e7d0ecf214224bdc1.png)```//
|
1
|
+
](4df38266afa79b4e7d0ecf214224bdc1.png)![Fixを押したらバツが2つになります。(9fbe3fcb75ee29a91315a689bcfd21fc.png)```//
|
2
2
|
// ViewController.swift
|
3
3
|
// MyOkashi
|
4
4
|
//
|