私は解決策を待っている新しい問題があります。私は今、少し配線されたレイアウトを持っています。私のMainViewはTableViewであり、6つのカスタムセルの1つにTableViewを持つ1つのセルがあります。この内部のtableViewのセルをクリックすることで、私は新しいYTPlayerViewControllerへのセグを望みます。これは、グーグルYThelperクラスを使用してYouTubeビデオを見るためのビューです。prepareForSegue of custom UITableViewCell
問題は、これらの機能を知らないカスタムUITableViewCellクラスで処理する必要があるため、performSegueWithIdentifier
とoverride func prepareForSegue
のものが機能しません。
代替手段はありますか?
私は、ビデオIDをセルからYTPlayerViewControllerに転送し、それを開いてビデオを再生したいだけです。そこから戻ることができるはずです。
私は理解して助けてくれることを願っています。ドイツ
から
挨拶私のクラス:あなたのDetailVideoCellで
class DetailVideoCell: UITableViewCell , UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var selectedVideoIndex: Int!
/*override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "showPlayer" {
let playerViewController = segue.destinationViewController as! YTPlayerViewController
playerViewController.videoID = Data.youTubeVideos[selectedVideoIndex]["videoId"] as! String
}
}*/
// MARK: TableViewDataSource functions.
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Data.youTubeVideos.count ?? 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: VideoDetailCell = tableView.dequeueReusableCellWithIdentifier("VideoDetailCell") as! VideoDetailCell
let url = NSURL(string: Data.youTubeVideos[indexPath.row]["thumbnail"] as! String)
let data = NSData(contentsOfURL: url!)
let image = UIImage(data: data!)
cell.videoThumbnail.image = image
cell.channelTitle.text = Data.youTubeVideos[indexPath.row]["channelTitle"] as? String
cell.videoTitle.text = Data.youTubeVideos[indexPath.row]["title"] as? String
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedVideoIndex = indexPath.row
print(selectedVideoIndex)
//performSegueWithIdentifier("showPlayer", sender: indexPath)
}
}
をその原料が機能しなかった理由は? tableViewサブクラスではなく、あなたのtableViewコントローラクラスでそれらをハンドリングする必要があります。 –
ええ、私のtableviewコントローラは私のtableviewcellです – kuemme01
'UITableViewDelegate'はどこに実装していますか? – frankfg