簡體   English   中英

uitableview 標題視圖問題

[英]uitableview header view issue

我創建了一個 tableview,我有 2 個部分。 在第二部分我需要一個標題。 所以我像下面這樣做了。

  func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    if section == 1 {
        return 40
    }
    return 0
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if section == 1 {
        let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell

        return header
    }
    else {
        return nil
    }
}

我在重新加載 section.Header 時遇到問題。如果我執行 tableview.reload,它的工作正常。 會是什么問題?。 當我刪除單元格中的項目時,我也遇到了問題。 圖像如下。
在此處輸入圖片說明

標題獲取與編輯行相同的移動。

我檢查了從這里滑動刪除單元格導致 tableViewHeader 隨單元格移動的鏈接得到了答案。

而不是單元格返回 cell.contentview.both 問題已解決

       func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
         if section == 1 {
               let header = tableView.dequeueReusableCellWithIdentifier("audiocellheader")! as UITableViewCell
               return header.contentView
        }   
        else {
             return nil
        }
      }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM