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

回答編集履歴

1

追記

2015/04/03 13:21

投稿

at1994
at1994

スコア202

answer CHANGED
@@ -1,3 +1,52 @@
1
- ```lang-<ここに言語を入力
1
+ ```lang-<Objective-C
2
+
3
+ class MyView : UIView, UITableViewDelegate, UITableViewDataSource {
4
+
5
+ var tableView : UITableView? = UITableView(frame: rect)
6
+ var data : NSMutableArray = []
7
+
8
+ override init() {
9
+ super.init()
10
+ self.setUp()
2
- コード
11
+ }
12
+
13
+ override init(frame: CGRect) {
14
+ super.init(frame: frame)
15
+ self.setUp()
16
+ }
17
+
18
+ required init(coder aDecoder: NSCoder) {
19
+ super.init(coder: aDecoder)
20
+ self.setUp()
21
+ }
22
+
23
+ func setData(data : NSMutableArray) {
24
+ self.data = data
25
+ self.tableView?.reloadData()
26
+ }
27
+
28
+ func setUp() {
29
+ self.addSubview(self.tableView!)
30
+ self.tableView?.delegate = self
31
+ }
32
+
33
+ //①
34
+ func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
35
+ let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
36
+
37
+ cell.textLabel?.text = self.data[indexPath.row] as? String
38
+
39
+ return cell
40
+ }
41
+
42
+ //②
43
+ func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
44
+ return self.data.count
45
+ }
46
+
47
+ }
3
- ```
48
+ ```
49
+
50
+ UITableViewDataSourceプロトコルを紐付けた時、実装すべきメソッドが2つあります。
51
+ その2つのメソッドを実装すればエラーが消えると思うので試してみてください。
52
+ ソースコード上の①と②のメソッドです。