Ich habe eine UICollectionView, die in UITableViewCell ist. Ich habe 7 Knopf in UICollectionViewCell. Wenn ich Button1 drücke, sollten die Daten an einen anderen Viewcontroller übergeben werden, tut es aber nicht.So übergeben Sie Daten von UICollectionViewCell (in UITableviewCell) zu einem anderen UIViewcontroller Swift3
// TableviewCell
import UIKit
class backgroundViewCell: UITableViewCell {
var dayName : String!
var audioFileURL : String!
var tittle : String?
// guided collectionView
@IBOutlet var collectionView: UICollectionView!
let data = ["1","2","3","4","5","6","7"]
let images = ["circleblank","circleblank","circleblank","circleblank","circleblank","circleblank","circleblank"]
@IBOutlet var Labeltittle: UILabel!
@IBOutlet var LabelDetail: UILabel!
@IBOutlet var iconview: UIImageView!
extension backgroundViewCell : UICollectionViewDataSource, UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 7
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CollectionViewCell1", for: indexPath) as! CollectionViewCell
cell.Label.text = data[indexPath.row]
cell.ImageView.image = UIImage(named: images[indexPath.row])
let bgColorView = UIView()
bgColorView.backgroundColor = UIColor.clear
var imageView : UIImageView
imageView = UIImageView(frame:CGRect(x :4.1,y : 3.9, width: cell.ImageView.frame.size.width, height : cell.ImageView.frame.size.height));
imageView.image = UIImage(named : "blankoval")
bgColorView.addSubview(imageView)
cell.selectedBackgroundView = bgColorView
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("Collection view at row \(collectionView.tag) selected index path \(indexPath.row)")
switch (indexPath.row) {
case 0:
dayName = "Day 1"
self.audioFileURL = musicUrlFile.Day1
break
case 1:
self.audioFileURL = musicUrlFile.Day2
dayName = "Day 2"
break
case 2:
self.audioFileURL = musicUrlFile.Day3
dayName = "Day 3"
break
case 3:
self.audioFileURL = musicUrlFile.Day4
dayName = "Day 4"
break
case 4:
self.audioFileURL = musicUrlFile.Day5
dayName = "Day 5"
break
case 5:
self.audioFileURL = musicUrlFile.Day6
dayName = "Day 6"
break
default:
self.audioFileURL = musicUrlFile.Day7
dayName = "Day 7"
break
}
}
}
}
// Tableviewcontroller
import UIKit
class PlayerGuidedTableViewController: UITableViewController {
var audioFileURL : String!
var dayName : String!
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 1
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 600
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> backgroundViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "guidedPlayerCell") as! backgroundViewCell
cell.selectionStyle = .none
cell.playPauseButton.addTarget(self, action: #selector(PlayerGuidedTableViewController.playPauseButtonAction), for: .touchUpInside)
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "MainPlayer" {
if let collectionCell: backgroundViewCell = sender as? backgroundViewCell {
if let collectionView: UICollectionView = collectionCell.superview as? UICollectionView {
if let playerVC = segue.destination as? playerGuidedViewController {
playerVC.Day = dayName
playerVC.UrlAudio = audioFileURL
}
}
}
}
}
// override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// if segue.identifier == "guidedMainPlayer" {
//
// let playerVC = segue.destination as! playerGuidedViewController
// playerVC.Day = dayName
// playerVC.UrlAudio = audioFileURL
//
//
// }
// }
}
}
Danke für Ihre Antwort. Es funktioniert nicht wirklich. –
Was machst du? –
Was ist der Fehler aufgetreten? –