プロジェクトに4曲追加して、それをセルを選択することで鳴るようにしたいのですが、『Value of type "ViewController" has no member 'mytableview'』というエラーが出てしまいます。
<ViewControllerのコード>
import UIKit
import AVFoundation
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let imageNames = ["futako.jpg", "yokado.jpg", "fran.jpg", "zikken.jpg"] let imageTitles = ["イヌ2", "ネコ2", "イヌ1", "イヌ2"] let imageDescriptions = [ "イヌ", "ネコ", "イヌ", "イヌ" ] var audioPlayer = AVAudioPlayer() 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, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as! CustomTableViewCell cell.setCell(imageNames[indexPath.row], titleText: imageTitles[indexPath.row], descriptionText: imageDescriptions[indexPath.row]) return cell } @IBAction func tapButton(sender: AnyObject) { let btn = sender as! UIButton let cell = btn.superview?.superview as! UITableViewCell let row = self.mytableview.indexPathForCell(cell)?.row //(この上のコードの箇所でエラーが発生します) let fileName = "sound\(row! + 1)" print(fileName) //let soundPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(fileName, ofType: "mp3")!)
}
}
<CustomTableViewCellのコード>
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! 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件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/02 11:55
2016/09/02 12:16 編集
2016/09/03 11:32