我有一個分組表格視圖,我想要自定義節標題。但我無法顯示錶格視圖的第一個部分標題。第一個分組表格視圖區域標題不顯示
我有兩個部分,用於第一部分節頭沒有顯示,但是第二個是:
我看到類似的問題,其中,通過實施heightForHeaderInSection
但我解決了這些問題已經實現了。
我設置部分是這樣的:
let kSectionHeaderContact: String = "CONTACT INFORMATION"
let kSectionHeaderFeedback: String = "FEEDBACK"
enum Sections: Int {
case ContactSection = 0
case FeedbackSection = 1
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == Sections.ContactSection.rawValue {
return contactObjectsDictionary.count
} else if section == Sections.FeedbackSection.rawValue {
return feedbackObjectsDictionary.count
} else {
return 0
}
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if section == Sections.ContactSection.rawValue {
sectionHeaderView.sectionHeaderTitle.text = kSectionHeaderContact
} else if section == Sections.FeedbackSection.rawValue {
sectionHeaderView.sectionHeaderTitle.text = kSectionHeaderFeedback
}
return sectionHeaderView
}
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return kContactTableViewSectionHeaderViewHeight
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifierContactTableViewCell, forIndexPath: indexPath) as! ContactTableViewCell
// Configure the cell...
var titleText: String = ""
var detailText: String = ""
if indexPath.section == Sections.ContactSection.rawValue {
let contactObject = contactObjectsDictionary[indexPath.row]
titleText = contactObject[kDictionaryTitleKey]!
detailText = contactObject[kDictionaryDetailKey]!
} else if indexPath.section == Sections.FeedbackSection.rawValue {
let feedbackObject = feedbackObjectsDictionary[indexPath.row]
titleText = feedbackObject[kDictionaryTitleKey]!
detailText = feedbackObject[kDictionaryDetailKey]!
}
cell.configureCell(titleText, detail: detailText)
return cell
}
我執行在我的故事板自定義欄目標題,然後通過出口引用它:
編輯: 我希望能夠在故事板中設計我的自定義部分標題,而不是以編程方式。
但爲什麼我不能使用我的視圖從故事板有@IBOutlet var sectionHeaderView:ContactTableViewSectionHeaderView!參考?它有一個類「ContactTableViewSectionHeaderView」,它是UIView的子類 – Oskariagon
因爲它只是UIView的單個實例&你只能使用它一次。或者創建新的實例。 –
好吧,所以viewForHeaderInSection像重用表格視圖單元格一樣工作?但是我應該能夠從故事板中使用我自己定製的UIView子類?我想在故事板中設計它,然後將其實現爲節標題。 – Oskariagon