『0x109ec616b <+43>: movq %rdi, -0x68(%rbp)』という表示の横にThread1:breakpoint1.1というものが表示され、実行ができなかったので、ネットで対処法を調べたらBreakPointsを削除したらいいと書かれていたので、削除しました。
すると実行でできたのですが、今度は、Buttonを押すと、『Thread 1: signal SIGABRT』というものが出るようになりました。そして、その対処法を調べるとBreakPointを追加しろと書かれているサイトを見つけました。
しかし、BreakPointsを追記せず、Buttonを右クリックして、出てきたメニューの注意マーク(!?)のようなものがついているところの左にある❌を押し、再度実行すると、Buttonを押すたびにOptional([0, 0])やOptional([0, 1])といったものがデバッグエリアに追加され続け、音が鳴りません。
BreakPointsは削除していいものなのでしょうか。
参考までに、以下にコードを記載しておきます。
ナビゲーターエリアに
画像としてfutako.jpg, yokado.jpg, fran.jpg, zikken.jpgを
音源としてsound01,sound02,sound03,sound04を追加してあります。
// ViewController.swift import UIKit import AVFoundation class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { let imageNames = ["futako.jpg", "fran.jpg","yokado.jpg", "zikken.jpg"] @IBOutlet weak var tableView: UITableView! let imageTitles = ["イヌ", "イヌ", "ネコ", "ネコ"] var audioPlayer = AVAudioPlayer() let imageDescriptions = [ "2018/10/30", "2018/10/30", "2018/10/30", "2018/10/30" ] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return imageNames.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! CustomTableViewCell cell.setCell(imageNames[(indexPath as NSIndexPath).row], titleText: imageTitles[(indexPath as NSIndexPath).row], descriptionText: imageDescriptions[(indexPath as NSIndexPath).row]) cell.index = indexPath // cell.delegate = self return cell } func selectCellButton(_ index: IndexPath) { let fileName = String(format: "sound%02d", index.row+1) print(fileName) do { let filePath = Bundle.main.path(forResource: fileName, ofType: "mp3") let audioPath = URL(fileURLWithPath: filePath!) audioPlayer = try AVAudioPlayer(contentsOf: audioPath) if audioPlayer.prepareToPlay() { audioPlayer.play() } } catch { print("Error") } } @IBAction func tapButton(_ sender: UIButton) { var hoge = sender.superview while(hoge!.isKind(of: UITableViewCell.self) == false) { hoge = hoge!.superview } let cell = hoge as! UITableViewCell let indexPath = self.tableView.indexPath(for: cell) print(indexPath) self.selectCellButton(index) } }
<ここからはCustomTableViewCellのコードです> // CustomTableViewCell.swift import UIKit class CustomTableViewCell: UITableViewCell { @IBOutlet weak var myImageView: UIImageView! @IBOutlet weak var myTitleLabel: UILabel! @IBOutlet weak var myDescriptionLabel: UILabel! @IBOutlet weak var tapButton: UIButton! // weak var delegate: CustomTableViewCellDelegate! var index: IndexPath! override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } func setCell(_ imageName: String, titleText: String, descriptionText: String) { myImageView.image = UIImage(named: imageName) myTitleLabel.text = titleText myDescriptionLabel.text = descriptionText } }
こちらの質問が複数のユーザーから「過去の低評価」という指摘を受けました。
回答1件