質問編集履歴

3

追記

2016/12/22 02:44

投稿

YonamineTK
YonamineTK

score42

test CHANGED
File without changes
test CHANGED
@@ -140,6 +140,24 @@
140
140
 
141
141
 
142
142
 
143
+ // Segue 準備
144
+
145
+ override func prepare(for segue: UIStoryboardSegue, sender: Any!) {
146
+
147
+ if (segue.identifier == "toSubViewController") {
148
+
149
+ let subVC: SubViewController = (segue.destination as? SubViewController)!
150
+
151
+ // SubViewController のselectedImgに選択された画像を設定する
152
+
153
+ subVC.selectedImg = selectedImage
154
+
155
+ }
156
+
157
+ }
158
+
159
+
160
+
143
161
  ```
144
162
 
145
163
  :参考元

2

追記

2016/12/22 02:44

投稿

YonamineTK
YonamineTK

score42

test CHANGED
File without changes
test CHANGED
@@ -20,19 +20,39 @@
20
20
 
21
21
  ```ここに言語を入力
22
22
 
23
- var friends:[Friend] = [Friend]()```
23
+ var friends:[Friend] = [Friend]()
24
24
 
25
25
 
26
26
 
27
+ override func viewDidLoad() {
28
+
29
+ super.viewDidLoad()
30
+
31
+
32
+
33
+ self.setupFriends()
34
+
35
+ self.tableView.delegate = self
36
+
37
+ self.tableView.detaSource = self
38
+
39
+
40
+
41
+ }
42
+
43
+
44
+
45
+ //参考元:http://qiita.com/BigSea/items/9aa35b95e5d4d1dc8a52
46
+
27
47
  func setupFriends() {
28
48
 
29
- var f1 = Friend(itemName: "AAA", imageUrl: NSURL(string: "https://AAA"))
49
+ var f1 = Friend(itemName: "Google1", imageUrl: NSURL(string: "https://storage.googleapis.com/gweb-uniblog-publish-prod/static/blog/images/google-200x200.7714256da16f.png"))
30
50
 
31
- var f2 = Friend(itemName: "BBB", imageUrl: NSURL(string: "https://BBB"))
51
+ var f2 = Friend(itemName: "Google2", imageUrl: NSURL(string: "https://pbs.twimg.com/profile_images/809064074998710272/KJvmreRz_400x400.jpg"))
32
52
 
33
- var f3 = Friend(itemName: "CCC", imageUrl: NSURL(string: "https://CCC"))
53
+ var f3 = Friend(itemName: "Google3", imageUrl: NSURL(string: "https://lh3.googleusercontent.com/nYhPnY2I-e9rpqnid9u9aAODz4C04OycEGxqHG5vxFnA35OGmLMrrUmhM9eaHKJ7liB-=w300"))
34
54
 
35
- var f4 = Friend(itemName: "DDD", imageUrl: NSURL(string: "https://DDD"))
55
+ var f4 = Friend(itemName: "Google4", imageUrl: NSURL(string: "https://lh3.googleusercontent.com/7clxDYpmA-L1XXJP7wcRZMWV71MwDtZhubp1cF8Ss4cVjHFsqisncNP5vavacmMPhds=w300"))
36
56
 
37
57
 
38
58
 
@@ -48,9 +68,21 @@
48
68
 
49
69
  }
50
70
 
71
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
51
72
 
52
73
 
74
+
75
+ let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as CustomCell
76
+
77
+
78
+
79
+ cell.setCell(friends[indexPath.row])
80
+
81
+
82
+
83
+ return cell
84
+
53
- ```
85
+ }
54
86
 
55
87
 
56
88
 
@@ -58,7 +90,37 @@
58
90
 
59
91
  ```
60
92
 
93
+
94
+
95
+ ```
96
+
61
- // Cell が選択された場合
97
+ //CustomCellクラス
98
+
99
+ func setCell(friend :Friend) {
100
+
101
+ self.itemName.text = friend.itemName
102
+
103
+ do {
104
+
105
+ let imageData :NSData = try NSData(contentsOfURL: friend.imageUrl!,options: NSDataReadingOptions.DataReadingMappedIfSafe)
106
+
107
+ self.siteImage.image = UIImage(data:imageData)
108
+
109
+ } catch {
110
+
111
+ print("Error: can't create image.")
112
+
113
+ }
114
+
115
+ }
116
+
117
+ ```
118
+
119
+
120
+
121
+ ```
122
+
123
+ // 参考元:https://iphone-app-tec.com/ios/tableview-cell.html
62
124
 
63
125
  func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
64
126
 

1

参考元の追記

2016/12/22 02:30

投稿

YonamineTK
YonamineTK

score42

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,9 @@
79
79
 
80
80
 
81
81
  ```
82
+
83
+ :参考元
84
+
85
+ https://iphone-app-tec.com/ios/tableview-cell.html
86
+
87
+ http://qiita.com/BigSea/items/9aa35b95e5d4d1dc8a52