回答編集履歴

5

s

2018/05/23 14:26

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -18,31 +18,63 @@
18
18
 
19
19
  ```swift
20
20
 
21
+
22
+
21
23
  import UIKit
22
24
 
23
25
  import TTTAttributedLabel
24
26
 
25
27
 
26
28
 
27
- class ViewController: UIViewController, TTTAttributedLabelDelegate {
29
+ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
28
30
 
29
31
 
30
32
 
31
- @IBOutlet weak var label1: TTTAttributedLabel!
33
+ @IBOutlet weak var tableView: UITableView!
32
34
 
33
35
 
34
36
 
35
- override func viewDidLoad() {
37
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
36
38
 
37
- super.viewDidLoad()
39
+ return 3
38
40
 
39
-
41
+ }
40
42
 
41
- label1.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
43
+
42
44
 
43
- label1.text = "URLにタップできます。\nhttps://www.google.co.jp/"
45
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
44
46
 
47
+ if let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath as IndexPath) as? CustomCell {
48
+
49
+ cell.setText(text: "URLにタップできます。\nhttps://www.google.co.jp/")
50
+
51
+ return cell
52
+
53
+ }
54
+
55
+ return UITableViewCell()
56
+
57
+ }
58
+
59
+ }
60
+
61
+
62
+
63
+ class CustomCell: UITableViewCell, TTTAttributedLabelDelegate {
64
+
65
+
66
+
67
+ @IBOutlet weak var label: TTTAttributedLabel!
68
+
69
+
70
+
71
+ func setText(text: String) {
72
+
73
+ label.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
74
+
75
+ label.text = text
76
+
45
- label1.delegate = self
77
+ label.delegate = self
46
78
 
47
79
  }
48
80
 
@@ -57,3 +89,7 @@
57
89
  }
58
90
 
59
91
  ```
92
+
93
+
94
+
95
+ ![](a7d474040a01047c2450a88f0465d037.png)

4

s

2018/05/23 14:26

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -7,3 +7,53 @@
7
7
 
8
8
 
9
9
  それでも解決しなければコンソールに出ているエラーをすべて載せてください。
10
+
11
+
12
+
13
+ 回答追記
14
+
15
+ ---
16
+
17
+
18
+
19
+ ```swift
20
+
21
+ import UIKit
22
+
23
+ import TTTAttributedLabel
24
+
25
+
26
+
27
+ class ViewController: UIViewController, TTTAttributedLabelDelegate {
28
+
29
+
30
+
31
+ @IBOutlet weak var label1: TTTAttributedLabel!
32
+
33
+
34
+
35
+ override func viewDidLoad() {
36
+
37
+ super.viewDidLoad()
38
+
39
+
40
+
41
+ label1.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
42
+
43
+ label1.text = "URLにタップできます。\nhttps://www.google.co.jp/"
44
+
45
+ label1.delegate = self
46
+
47
+ }
48
+
49
+
50
+
51
+ func attributedLabel(_ label: TTTAttributedLabel!, didSelectLinkWith url: URL!) {
52
+
53
+ print("Tapped!")
54
+
55
+ }
56
+
57
+ }
58
+
59
+ ```

3

s

2018/05/23 13:25

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -3,3 +3,7 @@
3
3
 
4
4
 
5
5
  ![イメージ説明](1150f45f961e796fc27dbc6c9428e54b.png)
6
+
7
+
8
+
9
+ それでも解決しなければコンソールに出ているエラーをすべて載せてください。

2

s

2018/05/22 22:32

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1 +1,5 @@
1
1
  `Storyboard` or `xib`にラベルを配置していると思いますが、そのラベルの`Custom Class` は`TTTAttributedLabel`になっているでしょうか?
2
+
3
+
4
+
5
+ ![イメージ説明](1150f45f961e796fc27dbc6c9428e54b.png)

1

s

2018/05/22 22:30

投稿

_Kentarou
_Kentarou

スコア8490

test CHANGED
@@ -1,9 +1 @@
1
- > エラー文には
2
-
3
- libc++abi.dylib: terminating with uncaught exception of type NSException
1
+ `Storyboard` or `xib`にラベルを配置していると思いますが、そのラベルの`Custom Class` は`TTTAttributedLabel`になっているでしょうか?
4
-
5
-
6
-
7
- エラーにはおそらく`TTTAttributedLabel`のライブラリは関係ないとおもいます。
8
-
9
- それ以外のコンソールに表示されているエラー文言を追記してください。