我有一个填充了歌曲标题和艺术家的表格视图。我有一台服务器,我从那里检索歌曲。我第一次点击时效果非常好,但是当我点击另一个单元格时,我收到错误fatal error: unexpectedly found nil while unwrapping an Optional value
。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell: VenueCell = table.cellForRowAtIndexPath(indexPath) as! VenueCell
cell.songtitle.textColor = UIColor.whiteColor()
cell.songartist.textColor = UIColor.whiteColor()
controltitle.text = songtitles[indexPath.row]
controlartist.text = songartists[indexPath.row]
let spacesongs = songtitles[indexPath.row].stringByReplacingOccurrencesOfString(" ", withString: "%20", options: NSStringCompareOptions.LiteralSearch, range: nil)
if let url: String = "hiding link"{
let urlplayer = NSURL(string: url)
let playeritem = AVPlayerItem(URL:(urlplayer)!)
player = AVPlayer(playerItem: playeritem)
print(url)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification, object: playeritem)
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target: self, selector:Selector("setProgress"), userInfo: nil, repeats: true)
print(counter)
print("current \(CMTimeGetSeconds(playeritem.currentTime()))")
self.player.volume = 1.0
self.player.rate = 1.0
self.player.play()
playpause.setImage(UIImage(named: "Pause"), forState: .Normal)
}