質問編集履歴
5
コードを現状のものに修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,29 +18,27 @@
|
|
18
18
|
import AVFoundation
|
19
19
|
|
20
20
|
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
21
|
-
|
22
21
|
|
23
|
-
let imageNames = ["futako.jpg", "yokado.jpg", "fran.jpg", "zikken.jpg"]
|
24
22
|
|
23
|
+
let imageNames = ["futako.jpg", "fran.jpg","yokado.jpg", "zikken.jpg"]
|
25
24
|
|
26
25
|
@IBOutlet weak var tableView: UITableView!
|
27
26
|
|
28
|
-
|
29
|
-
let imageTitles = ["イヌ
|
27
|
+
let imageTitles = ["イヌ", "イヌ", "ネコ", "ネコ"]
|
30
28
|
var audioPlayer = AVAudioPlayer()
|
31
29
|
|
32
30
|
let imageDescriptions = [
|
33
|
-
"
|
31
|
+
"2018/10/30",
|
34
|
-
"
|
32
|
+
"2018/10/30",
|
35
|
-
"
|
33
|
+
"2018/10/30",
|
36
|
-
"
|
34
|
+
"2018/10/30"
|
37
35
|
]
|
38
|
-
|
36
|
+
|
39
37
|
override func viewDidLoad() {
|
40
38
|
super.viewDidLoad()
|
41
39
|
// Do any additional setup after loading the view, typically from a nib.
|
42
40
|
}
|
43
|
-
|
41
|
+
|
44
42
|
override func didReceiveMemoryWarning() {
|
45
43
|
super.didReceiveMemoryWarning()
|
46
44
|
// Dispose of any resources that can be recreated.
|
@@ -62,7 +60,7 @@
|
|
62
60
|
}
|
63
61
|
|
64
62
|
func selectCellButton(_ index: IndexPath) {
|
65
|
-
let fileName = "sound
|
63
|
+
let fileName = String(format: "sound%02d", index.row+1)
|
66
64
|
|
67
65
|
print(fileName)
|
68
66
|
|
@@ -76,8 +74,9 @@
|
|
76
74
|
} catch {
|
77
75
|
print("Error")
|
78
76
|
}
|
79
|
-
}
|
77
|
+
}
|
80
78
|
|
79
|
+
|
81
80
|
@IBAction func tapButton(_ sender: UIButton) {
|
82
81
|
var hoge = sender.superview
|
83
82
|
|
@@ -86,26 +85,24 @@
|
|
86
85
|
}
|
87
86
|
|
88
87
|
let cell = hoge as! UITableViewCell
|
89
|
-
|
88
|
+
|
90
89
|
let indexPath = self.tableView.indexPath(for: cell)
|
91
90
|
|
92
91
|
print(indexPath)
|
93
|
-
|
92
|
+
|
94
|
-
|
93
|
+
self.selectCellButton(index)
|
95
94
|
}
|
96
95
|
}
|
96
|
+
|
97
97
|
```
|
98
98
|
```
|
99
99
|
<ここからはCustomTableViewCellのコードです>
|
100
100
|
// CustomTableViewCell.swift
|
101
101
|
import UIKit
|
102
102
|
|
103
|
-
|
104
|
-
|
105
103
|
class CustomTableViewCell: UITableViewCell {
|
106
104
|
|
107
105
|
|
108
|
-
|
109
106
|
@IBOutlet weak var myImageView: UIImageView!
|
110
107
|
|
111
108
|
@IBOutlet weak var myTitleLabel: UILabel!
|
@@ -115,7 +112,6 @@
|
|
115
112
|
@IBOutlet weak var tapButton: UIButton!
|
116
113
|
|
117
114
|
|
118
|
-
|
119
115
|
// weak var delegate: CustomTableViewCellDelegate!
|
120
116
|
var index: IndexPath!
|
121
117
|
|
@@ -132,9 +128,10 @@
|
|
132
128
|
|
133
129
|
func setCell(_ imageName: String, titleText: String, descriptionText: String) {
|
134
130
|
myImageView.image = UIImage(named: imageName)
|
135
|
-
myTitleLabel.text = titleText
|
131
|
+
myTitleLabel.text = titleText
|
136
|
-
myDescriptionLabel.text = descriptionText
|
132
|
+
myDescriptionLabel.text = descriptionText
|
137
133
|
}
|
138
134
|
|
139
135
|
}
|
136
|
+
|
140
137
|
```
|
4
追記しました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Breakpointsは削除していいものなのか?
|
body
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができなかったので、ネットで対処法を調べたら
|
1
|
+
『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができなかったので、ネットで対処法を調べたらBreakPointsを削除したらいいと書かれていたので、削除しました。
|
2
2
|
すると実行でできたのですが、今度は、Buttonを押すと、『Thread 1: signal SIGABRT』というものが出るようになりました。そして、その対処法を調べるとBreakPointを追加しろと書かれているサイトを見つけました。
|
3
|
+
しかし、BreakPointsを追記せず、Buttonを右クリックして、出てきたメニューの注意マーク(!?)のようなものがついているところの左にある❌を押し、再度実行すると、Buttonを押すたびにOptional([0, 0])やOptional([0, 1])といったものがデバッグエリアに追加され続け、音が鳴りません。
|
3
4
|
|
4
|
-
|
5
|
+
BreakPointsは削除していいものなのでしょうか。
|
5
6
|
|
6
7
|
|
7
8
|
参考までに、以下にコードを記載しておきます。
|
3
追記しました
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
Breakpointは削除していいものなのか?
|
body
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
delegateとdetaSourceをViewControllerに設定してない場合、エラーも出ないのですが、実行すると何も表示されない。delegateとdetaSourceをViewControllerに設定すると、
|
2
|
-
『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができな
|
1
|
+
『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができなかったので、ネットで対処法を調べたらBreakPointを削除したらいいと書かれていたので、削除しました。
|
3
|
-
|
2
|
+
すると実行でできたのですが、今度は、Buttonを押すと、『Thread 1: signal SIGABRT』というものが出るようになりました。そして、その対処法を調べるとBreakPointを追加しろと書かれているサイトを見つけました。
|
4
3
|
|
4
|
+
BreakPointは削除していいものなのでしょうか。
|
5
5
|
|
6
|
+
|
6
7
|
参考までに、以下にコードを記載しておきます。
|
7
8
|
ナビゲーターエリアに
|
8
9
|
画像としてfutako.jpg, yokado.jpg, fran.jpg, zikken.jpgを
|
@@ -135,9 +136,4 @@
|
|
135
136
|
}
|
136
137
|
|
137
138
|
}
|
138
|
-
```
|
139
|
+
```
|
139
|
-
|
140
|
-
|
141
|
-
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
142
|
-
上記のコードを実行すると、Cellのラインは表示されるのですが、
|
143
|
-
イメージ、ラベルは表示されず、音を鳴らすこともできません。
|
2
質問内容を少し変えてみました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
|
1
|
+
delegateとdetaSourceをViewControllerに設定してない場合、エラーも出ないのですが、実行すると何も表示されない。delegateとdetaSourceをViewControllerに設定すると、
|
2
|
+
『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができなくなります。
|
3
|
+
どのように原因を特定したらよいでしょうか。
|
2
4
|
|
5
|
+
|
6
|
+
参考までに、以下にコードを記載しておきます。
|
3
7
|
ナビゲーターエリアに
|
4
8
|
画像としてfutako.jpg, yokado.jpg, fran.jpg, zikken.jpgを
|
5
9
|
音源としてsound01,sound02,sound03,sound04を追加してあります。
|
6
10
|
|
7
|
-
以下、コードになります。
|
8
11
|
|
12
|
+
```
|
9
13
|
// ViewController.swift
|
10
14
|
|
11
15
|
import UIKit
|
@@ -88,8 +92,8 @@
|
|
88
92
|
// delegate?.selectCellButton(index)
|
89
93
|
}
|
90
94
|
}
|
91
|
-
|
95
|
+
```
|
92
|
-
|
96
|
+
```
|
93
97
|
<ここからはCustomTableViewCellのコードです>
|
94
98
|
// CustomTableViewCell.swift
|
95
99
|
import UIKit
|
@@ -131,9 +135,9 @@
|
|
131
135
|
}
|
132
136
|
|
133
137
|
}
|
138
|
+
```
|
134
139
|
|
135
140
|
|
136
|
-
|
137
141
|
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
138
142
|
上記のコードを実行すると、Cellのラインは表示されるのですが、
|
139
143
|
イメージ、ラベルは表示されず、音を鳴らすこともできません。
|
1
コードを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,1 +1,139 @@
|
|
1
|
-
コードに問題がなく、エラーも出ないのですが、実行すると何も表示されない。その場合、何が関係しているのでしょうか。
|
1
|
+
コードに問題がなく、エラーも出ないのですが、実行すると何も表示されない。その場合、何が関係しているのでしょうか。
|
2
|
+
|
3
|
+
ナビゲーターエリアに
|
4
|
+
画像としてfutako.jpg, yokado.jpg, fran.jpg, zikken.jpgを
|
5
|
+
音源としてsound01,sound02,sound03,sound04を追加してあります。
|
6
|
+
|
7
|
+
以下、コードになります。
|
8
|
+
|
9
|
+
// ViewController.swift
|
10
|
+
|
11
|
+
import UIKit
|
12
|
+
import AVFoundation
|
13
|
+
|
14
|
+
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
|
15
|
+
|
16
|
+
|
17
|
+
let imageNames = ["futako.jpg", "yokado.jpg", "fran.jpg", "zikken.jpg"]
|
18
|
+
|
19
|
+
|
20
|
+
@IBOutlet weak var tableView: UITableView!
|
21
|
+
|
22
|
+
|
23
|
+
let imageTitles = ["イヌ2", "ネコ2", "イヌ1", "イヌ2"]
|
24
|
+
var audioPlayer = AVAudioPlayer()
|
25
|
+
|
26
|
+
let imageDescriptions = [
|
27
|
+
"イヌ",
|
28
|
+
"ネコ",
|
29
|
+
"イヌ",
|
30
|
+
"イヌ"
|
31
|
+
]
|
32
|
+
|
33
|
+
override func viewDidLoad() {
|
34
|
+
super.viewDidLoad()
|
35
|
+
// Do any additional setup after loading the view, typically from a nib.
|
36
|
+
}
|
37
|
+
|
38
|
+
override func didReceiveMemoryWarning() {
|
39
|
+
super.didReceiveMemoryWarning()
|
40
|
+
// Dispose of any resources that can be recreated.
|
41
|
+
}
|
42
|
+
|
43
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
44
|
+
return imageNames.count
|
45
|
+
}
|
46
|
+
|
47
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
48
|
+
|
49
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! CustomTableViewCell
|
50
|
+
|
51
|
+
cell.setCell(imageNames[(indexPath as NSIndexPath).row], titleText: imageTitles[(indexPath as NSIndexPath).row], descriptionText: imageDescriptions[(indexPath as NSIndexPath).row])
|
52
|
+
cell.index = indexPath
|
53
|
+
// cell.delegate = self
|
54
|
+
|
55
|
+
return cell
|
56
|
+
}
|
57
|
+
|
58
|
+
func selectCellButton(_ index: IndexPath) {
|
59
|
+
let fileName = "sound\((index as NSIndexPath).row + 1)"
|
60
|
+
|
61
|
+
print(fileName)
|
62
|
+
|
63
|
+
do {
|
64
|
+
let filePath = Bundle.main.path(forResource: fileName, ofType: "mp3")
|
65
|
+
let audioPath = URL(fileURLWithPath: filePath!)
|
66
|
+
audioPlayer = try AVAudioPlayer(contentsOf: audioPath)
|
67
|
+
if audioPlayer.prepareToPlay() {
|
68
|
+
audioPlayer.play()
|
69
|
+
}
|
70
|
+
} catch {
|
71
|
+
print("Error")
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
@IBAction func tapButton(_ sender: UIButton) {
|
76
|
+
var hoge = sender.superview
|
77
|
+
|
78
|
+
while(hoge!.isKind(of: UITableViewCell.self) == false) {
|
79
|
+
hoge = hoge!.superview
|
80
|
+
}
|
81
|
+
|
82
|
+
let cell = hoge as! UITableViewCell
|
83
|
+
|
84
|
+
let indexPath = self.tableView.indexPath(for: cell)
|
85
|
+
|
86
|
+
print(indexPath)
|
87
|
+
|
88
|
+
// delegate?.selectCellButton(index)
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
<ここからはCustomTableViewCellのコードです>
|
94
|
+
// CustomTableViewCell.swift
|
95
|
+
import UIKit
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
class CustomTableViewCell: UITableViewCell {
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
@IBOutlet weak var myImageView: UIImageView!
|
104
|
+
|
105
|
+
@IBOutlet weak var myTitleLabel: UILabel!
|
106
|
+
|
107
|
+
@IBOutlet weak var myDescriptionLabel: UILabel!
|
108
|
+
|
109
|
+
@IBOutlet weak var tapButton: UIButton!
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
// weak var delegate: CustomTableViewCellDelegate!
|
114
|
+
var index: IndexPath!
|
115
|
+
|
116
|
+
override func awakeFromNib() {
|
117
|
+
super.awakeFromNib()
|
118
|
+
// Initialization code
|
119
|
+
}
|
120
|
+
|
121
|
+
override func setSelected(_ selected: Bool, animated: Bool) {
|
122
|
+
super.setSelected(selected, animated: animated)
|
123
|
+
|
124
|
+
// Configure the view for the selected state
|
125
|
+
}
|
126
|
+
|
127
|
+
func setCell(_ imageName: String, titleText: String, descriptionText: String) {
|
128
|
+
myImageView.image = UIImage(named: imageName)
|
129
|
+
myTitleLabel.text = titleText
|
130
|
+
myDescriptionLabel.text = descriptionText
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
138
|
+
上記のコードを実行すると、Cellのラインは表示されるのですが、
|
139
|
+
イメージ、ラベルは表示されず、音を鳴らすこともできません。
|