Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active April 17, 2016 05:10
Show Gist options
  • Save KentarouKanno/2b1be01743f35bc5e3a50e5be0e84530 to your computer and use it in GitHub Desktop.
Save KentarouKanno/2b1be01743f35bc5e3a50e5be0e84530 to your computer and use it in GitHub Desktop.
ExtraView

ExtraView

★ ExtraViewをUITableViewのSectionHeaderに使用する場合の注意

@IBOutlet var sectionTitleView: SectionHeaderView!

// Custom SectionHeader
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    
    // コピーしたViewを渡さないと消えたり挙動が変になる。
    // ※プロパティに値を設定する場合はコピーする前に行う
    sectionTitleView.sectionTitleLabel.text = sectionTitleArray[section]
    let copiedSection = NSKeyedUnarchiver.unarchiveObjectWithData(NSKeyedArchiver.archivedDataWithRootObject(self.sectionTitleView)) as! SectionHeaderView
    return copiedSection
}

// SectionHeader Height
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return self.sectionTitleView.frame.size.height
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment