回答編集履歴

1

追記

2015/04/03 13:21

投稿

at1994
at1994

スコア202

test CHANGED
@@ -1,5 +1,103 @@
1
- ```lang-<ここに言語を入力
1
+ ```lang-<Objective-C
2
2
 
3
+
4
+
5
+ class MyView : UIView, UITableViewDelegate, UITableViewDataSource {
6
+
7
+
8
+
9
+ var tableView : UITableView? = UITableView(frame: rect)
10
+
11
+ var data : NSMutableArray = []
12
+
13
+
14
+
15
+ override init() {
16
+
17
+ super.init()
18
+
19
+ self.setUp()
20
+
3
- コード
21
+ }
22
+
23
+
24
+
25
+ override init(frame: CGRect) {
26
+
27
+ super.init(frame: frame)
28
+
29
+ self.setUp()
30
+
31
+ }
32
+
33
+
34
+
35
+ required init(coder aDecoder: NSCoder) {
36
+
37
+ super.init(coder: aDecoder)
38
+
39
+ self.setUp()
40
+
41
+ }
42
+
43
+
44
+
45
+ func setData(data : NSMutableArray) {
46
+
47
+ self.data = data
48
+
49
+ self.tableView?.reloadData()
50
+
51
+ }
52
+
53
+
54
+
55
+ func setUp() {
56
+
57
+ self.addSubview(self.tableView!)
58
+
59
+ self.tableView?.delegate = self
60
+
61
+ }
62
+
63
+
64
+
65
+ //①
66
+
67
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
68
+
69
+ let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
70
+
71
+
72
+
73
+ cell.textLabel?.text = self.data[indexPath.row] as? String
74
+
75
+
76
+
77
+ return cell
78
+
79
+ }
80
+
81
+
82
+
83
+ //②
84
+
85
+ func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
86
+
87
+ return self.data.count
88
+
89
+ }
90
+
91
+
92
+
93
+ }
4
94
 
5
95
  ```
96
+
97
+
98
+
99
+ UITableViewDataSourceプロトコルを紐付けた時、実装すべきメソッドが2つあります。
100
+
101
+ その2つのメソッドを実装すればエラーが消えると思うので試してみてください。
102
+
103
+ ソースコード上の①と②のメソッドです。