2015-11-30 27 views
0

我有一個關於UITableView的問題。我想建立一個表格,第一行是我使用UIWebView播放視頻的靜態單元格。下面的其他行將是一個視頻列表。當我點擊列表中的視頻時,我想在第一行播放它。Swift UITableView didSelectRowAtIndexPath在multipleSection和多個原型單元格

任何人都可以幫助我設置功能didSelectRowAtIndexPath這種情況?非常感謝你。

這裏是我的代碼:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    if indexPath.section == 0 { 
     let cell2 = tableView.dequeueReusableCellWithIdentifier("staticCell", forIndexPath: indexPath) as! staticCell 
     let htmlString = "<video width='100%' webkit-playsinline controls autoplay ><source src= 'http://203.162.121.235:1935/live/tranhieuapt.rqv3-1d9w-hx44-5y3m/playlist.m3u8'></video>" 
     cell2.videoView.loadHTMLString(htmlString, baseURL: nil) 
     return cell2 
    } else if indexPath.section == 1 { 
     let cell = tableView.dequeueReusableCellWithIdentifier("dynamicCell", forIndexPath: indexPath) as! dynamicCell 
     // Get data function 
     func getDataFromUrl(url:NSURL, completion: ((data: NSData?, response: NSURLResponse?, error: NSError?) -> Void)) { 
      NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) in 
       completion(data: data, response: response, error: error) 
       }.resume() 
     } 
     // Download Image Function 
     func downloadImage(url: NSURL){ 
      getDataFromUrl(url) { (data, response, error) in 
       dispatch_async(dispatch_get_main_queue()) {() -> Void in 
        guard let data = data where error == nil else { return } 
        cell.thumnail.image = UIImage(data:data) 
       } 
      } 
     } 
     let vid = videoArray[indexPath.row] 

     cell.titleLb.text = vid.vidTitle 
     cell.viewLb.text = vid.vidView 
     cell.dateLb.text = vid.vidDate 


     let encodedUrl = vid.vidThumb.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) 
     if let checkedUrl = NSURL(string: encodedUrl!) { 
      cell.thumnail.contentMode = .ScaleAspectFit 
      downloadImage(checkedUrl) 
     } 

     return cell 
    } 
    let cell = UITableViewCell() 
    return cell 
} 
+2

如果你的問題中提到斯威夫特在標題和問題中的所有代碼用Swift編寫的,你正在尋找一個用Swift編寫的答案,你真的**不應該標記你的問題'objective-c'。 – Avi

回答

0

我認爲需要調整您的架構。

你需要有一個頂部(有玩家)和一個tableView下面的靜態viewdidSelectRowAtIndexPath只需更新播放器。

+0

謝謝你回答我的問題。但我想滾動我的觀點。如果我在頂部設置一個靜態視圖,那麼表格視圖的高度將太短。 –

+0

你想在'playerView'上進行垂直或水平滾動嗎? –

+0

首先,我用2個對象設計屏幕:用於播放視頻的UIWebview,用於顯示視頻列表的UITableView。然後我看到Table View的高度太短,我只看到列表中的2個視頻,而且很難使用UIRefreshControl。所以我想將所有對象添加到表視圖中,然後我可以滾動整個屏幕(就像在網絡中,我不想修復視頻播放器的位置)你能給我一個想法嗎?對不起我英文不好 –

0

您可以嘗試創建自定義視圖的tableView頭:

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
    let headerView = YourWebView() 

    return headerView 
} 

因此您`ll能夠滾動的一切

相關問題