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

質問編集履歴

3

追記

2016/12/22 02:44

投稿

YonamineTK
YonamineTK

スコア42

title CHANGED
File without changes
body CHANGED
@@ -69,6 +69,15 @@
69
69
  }
70
70
  }
71
71
 
72
+ // Segue 準備
73
+ override func prepare(for segue: UIStoryboardSegue, sender: Any!) {
74
+ if (segue.identifier == "toSubViewController") {
75
+ let subVC: SubViewController = (segue.destination as? SubViewController)!
76
+ // SubViewController のselectedImgに選択された画像を設定する
77
+ subVC.selectedImg = selectedImage
78
+ }
79
+ }
80
+
72
81
  ```
73
82
  :参考元
74
83
  https://iphone-app-tec.com/ios/tableview-cell.html

2

追記

2016/12/22 02:44

投稿

YonamineTK
YonamineTK

スコア42

title CHANGED
File without changes
body CHANGED
@@ -9,13 +9,23 @@
9
9
  回答、よろしくお願いします。
10
10
 
11
11
  ```ここに言語を入力
12
- var friends:[Friend] = [Friend]()```
12
+ var friends:[Friend] = [Friend]()
13
13
 
14
+ override func viewDidLoad() {
15
+ super.viewDidLoad()
16
+
17
+ self.setupFriends()
18
+ self.tableView.delegate = self
19
+ self.tableView.detaSource = self
20
+
21
+ }
22
+
23
+ //参考元:http://qiita.com/BigSea/items/9aa35b95e5d4d1dc8a52
14
24
  func setupFriends() {
15
- var f1 = Friend(itemName: "AAA", imageUrl: NSURL(string: "https://AAA"))
25
+ var f1 = Friend(itemName: "Google1", imageUrl: NSURL(string: "https://storage.googleapis.com/gweb-uniblog-publish-prod/static/blog/images/google-200x200.7714256da16f.png"))
16
- var f2 = Friend(itemName: "BBB", imageUrl: NSURL(string: "https://BBB"))
26
+ var f2 = Friend(itemName: "Google2", imageUrl: NSURL(string: "https://pbs.twimg.com/profile_images/809064074998710272/KJvmreRz_400x400.jpg"))
17
- var f3 = Friend(itemName: "CCC", imageUrl: NSURL(string: "https://CCC"))
27
+ var f3 = Friend(itemName: "Google3", imageUrl: NSURL(string: "https://lh3.googleusercontent.com/nYhPnY2I-e9rpqnid9u9aAODz4C04OycEGxqHG5vxFnA35OGmLMrrUmhM9eaHKJ7liB-=w300"))
18
- var f4 = Friend(itemName: "DDD", imageUrl: NSURL(string: "https://DDD"))
28
+ var f4 = Friend(itemName: "Google4", imageUrl: NSURL(string: "https://lh3.googleusercontent.com/7clxDYpmA-L1XXJP7wcRZMWV71MwDtZhubp1cF8Ss4cVjHFsqisncNP5vavacmMPhds=w300"))
19
29
 
20
30
  friends.append(f1)
21
31
  friends.append(f2)
@@ -23,12 +33,33 @@
23
33
  friends.append(f4)
24
34
 
25
35
  }
36
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell {
26
37
 
38
+ let cell: CustomCell = tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as CustomCell
39
+
40
+ cell.setCell(friends[indexPath.row])
41
+
42
+ return cell
43
+ }
44
+
45
+
27
46
  ```
28
47
 
48
+ ```
49
+ //CustomCellクラス
50
+ func setCell(friend :Friend) {
51
+ self.itemName.text = friend.itemName
52
+ do {
53
+ let imageData :NSData = try NSData(contentsOfURL: friend.imageUrl!,options: NSDataReadingOptions.DataReadingMappedIfSafe)
54
+ self.siteImage.image = UIImage(data:imageData)
55
+ } catch {
56
+ print("Error: can't create image.")
57
+ }
58
+ }
59
+ ```
29
60
 
30
61
  ```
31
- // Cell が選択された場合
62
+ // 参考元:https://iphone-app-tec.com/ios/tableview-cell.html
32
63
  func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
33
64
  // [indexPath.row] から画像名を探し、UImage を設定
34
65
  selectedImage = UIImage(named:"\(friends[indexPath.row])")

1

参考元の追記

2016/12/22 02:30

投稿

YonamineTK
YonamineTK

スコア42

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,7 @@
38
38
  }
39
39
  }
40
40
 
41
- ```
41
+ ```
42
+ :参考元
43
+ https://iphone-app-tec.com/ios/tableview-cell.html
44
+ http://qiita.com/BigSea/items/9aa35b95e5d4d1dc8a52