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

回答編集履歴

5

s

2018/05/23 14:26

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -8,23 +8,41 @@
8
8
  ---
9
9
 
10
10
  ```swift
11
+
11
12
  import UIKit
12
13
  import TTTAttributedLabel
13
14
 
14
- class ViewController: UIViewController, TTTAttributedLabelDelegate {
15
+ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
15
16
 
16
- @IBOutlet weak var label1: TTTAttributedLabel!
17
+ @IBOutlet weak var tableView: UITableView!
17
18
 
18
- override func viewDidLoad() {
19
- super.viewDidLoad()
20
-
21
- label1.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
19
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
22
- label1.text = "URLにタップできます。\nhttps://www.google.co.jp/"
23
- label1.delegate = self
20
+ return 3
24
21
  }
25
22
 
23
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
24
+ if let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath as IndexPath) as? CustomCell {
25
+ cell.setText(text: "URLにタップできます。\nhttps://www.google.co.jp/")
26
+ return cell
27
+ }
28
+ return UITableViewCell()
29
+ }
30
+ }
31
+
32
+ class CustomCell: UITableViewCell, TTTAttributedLabelDelegate {
33
+
34
+ @IBOutlet weak var label: TTTAttributedLabel!
35
+
36
+ func setText(text: String) {
37
+ label.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
38
+ label.text = text
39
+ label.delegate = self
40
+ }
41
+
26
42
  func attributedLabel(_ label: TTTAttributedLabel!, didSelectLinkWith url: URL!) {
27
43
  print("Tapped!")
28
44
  }
29
45
  }
30
- ```
46
+ ```
47
+
48
+ ![](a7d474040a01047c2450a88f0465d037.png)

4

s

2018/05/23 14:26

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -2,4 +2,29 @@
2
2
 
3
3
  ![イメージ説明](1150f45f961e796fc27dbc6c9428e54b.png)
4
4
 
5
- それでも解決しなければコンソールに出ているエラーをすべて載せてください。
5
+ それでも解決しなければコンソールに出ているエラーをすべて載せてください。
6
+
7
+ 回答追記
8
+ ---
9
+
10
+ ```swift
11
+ import UIKit
12
+ import TTTAttributedLabel
13
+
14
+ class ViewController: UIViewController, TTTAttributedLabelDelegate {
15
+
16
+ @IBOutlet weak var label1: TTTAttributedLabel!
17
+
18
+ override func viewDidLoad() {
19
+ super.viewDidLoad()
20
+
21
+ label1.enabledTextCheckingTypes = NSTextCheckingResult.CheckingType.link.rawValue
22
+ label1.text = "URLにタップできます。\nhttps://www.google.co.jp/"
23
+ label1.delegate = self
24
+ }
25
+
26
+ func attributedLabel(_ label: TTTAttributedLabel!, didSelectLinkWith url: URL!) {
27
+ print("Tapped!")
28
+ }
29
+ }
30
+ ```

3

s

2018/05/23 13:25

投稿

_Kentarou
_Kentarou

スコア8490

answer CHANGED
@@ -1,3 +1,5 @@
1
1
  `Storyboard` or `xib`にラベルを配置していると思いますが、そのラベルの`Custom Class` は`TTTAttributedLabel`になっているでしょうか?
2
2
 
3
- ![イメージ説明](1150f45f961e796fc27dbc6c9428e54b.png)
3
+ ![イメージ説明](1150f45f961e796fc27dbc6c9428e54b.png)
4
+
5
+ それでも解決しなければコンソールに出ているエラーをすべて載せてください。

2

s

2018/05/22 22:32

投稿

_Kentarou
_Kentarou

スコア8490

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

1

s

2018/05/22 22:30

投稿

_Kentarou
_Kentarou

スコア8490

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