0
오디오 제목이 나열된 테이블이 있습니다. 제목을 클릭하고 오디오 제목, 그림, 설명 및 재생 버튼을 표시하는 두 번째보기 컨트롤러로 이동합니다.테이블 셀을 클릭하여 여러 배열에서 두 번째보기 컨트롤러로 데이터 보내기
각 관련 데이터를 모두 보유한 4 개의 배열을 만들었지 만 두 번째보기 컨트롤러에서 imageView 및 단추를 사용하여 테이블의 행이 무엇으로 변경되는지 알 수 없습니다.
let audioTitile = ["Bubbling Pools", "March Of Faith"]
let audioImage = ["1.png", "2.png"]
let desc = ["The stench of life fills the air. Viscous fluid bubbles to the surface in great exhortations of gas and moisture. Something about these pools is familiar..",
"The devoted stream into the distance. The dust from their sandaled feet blocks out the sun for miles around. There's no stopping them. They believe."]
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return audioTitle.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
cell.textLabel?.text = audioTitle[indexPath.item]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "segue", sender: audioTitle[indexPath.row])
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let temp = segue.destination as! SecondViewController
temp.titleLabel.text = audioTitle[0] // need to replace [0] with ?
// temp.artworkImage.image = audioImage[0] This Code is wrong
temp.descriptionLabel.text = desc[0] // need to replace [0] with ?
}
@IBOutlet weak var tableView: UITableView!
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
제 2의보기 컨트롤러 코드 : 당신은 어떤 방법으로 배열을 포장한다
import UIKit
import AVFoundation
class SecondViewController: UIViewController {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var artworkImage: UIImageView!
@IBOutlet weak var descriptionLabel: UILabel!
@IBOutlet weak var playButton: UIButton!
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func playButtonPressed(_ sender: Any) {
playAudio()
}
var player: AVAudioPlayer?
func playAudio() {
let url = Bundle.main.url(forResource: "2_Bubbling_Pools.mp3", withExtension: "mp3")!
do {
player = try AVAudioPlayer(contentsOf: url)
guard let player = player else { return }
player.prepareToPlay()
player.play()
} catch let error {
print(error.localizedDescription)
}
}
}
이 답장을 보내 주셔서 감사합니다. 지금은 당연한 일이지만,이 코드 줄에서 두 번째보기 컨트롤러에 문제가 하나 있습니다. var selectedAudio : Audio! 당신은 별도의 Audio.swift 파일에이 코드를 배치해야 선언되지 않은 유형 '오디오' – Elfuthark
의 사용 : 구조체의 오디오를 { VAR 제목 : 문자열 var에 참고 ImageName : 문자열 var에 DESCR : 문자열} 좋은 일을하지만, 내가 설정 한주의 –
내 구조체에있는 모든 잘못된 문자열로, 내 이미지를이 var imageName으로 변경 작업 있어요. UIImage하지만 내가 바꿀 해야할지 확실하지 않습니다. var audioURL :이 문자열은 내 오디오 파일이어야합니다. 여기있는 모든 것은 내 오디오 파일 이름의 문자열 – Elfuthark