Ich habe einen UITableViewController mit einem Kopfansicht ähnlich:titleForHeaderInSection bewegen sich nicht
https://github.com/andersonkxiass/UITableViewHeader
Aber ich brauche einen Titel Header in meinem Tisch haben, an erster Stelle, es ist richtig, aber wenn ich starten den Tabellentitel bleibt statisch
dies ist mein Code zu bewegen:
class tableComent: UITableViewController {
var testComentName = [String]()
var headerView = UIView()
var viewHeight:CGFloat = 350 {
didSet {
moveHeader()
}
}
var scrollOffset:CGFloat = 0 {
didSet {
moveHeader()
}
}
private func loadNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
return bundle.loadNibNamed("headerTable", owner: nil, options: nil)[0] as! UIView
}
func moveHeader() {
let viewHeight = (scrollOffset >= 0) ? self.viewHeight : self.viewHeight - scrollOffset
headerView.frame = CGRect(x: 0, y: -viewHeight, width: view.bounds.width, height: viewHeight)
}
var backView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
headerView = loadNib()
backView.frame = CGRect(x: 0, y: 0 , width: view.bounds.width, height: view.bounds.height)
backView.backgroundColor = tableView.backgroundColor
view.addSubview(backView)
view.sendSubviewToBack(backView)
// Set the contentInset to make room for the image.
tableView.contentInset = UIEdgeInsets(top: viewHeight, left: 0, bottom: 0, right: 0)
// Add the imageView to the TableView and send it to the back.
view.addSubview(headerView)
view.sendSubviewToBack(headerView)
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
testComentName = ["Andres Gómez","Beatriz Gómez", "Francisco Manzo", "Rodolfo Martínez","Enrique Vega","Ana Lemus"]
loadTable()
}
override func viewWillAppear(animated: Bool) {
loadTable()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidLayoutSubviews() {
// Update the image position after layout changes.
moveHeader()
}
// Update scrollOffset on tableview scroll
override func scrollViewDidScroll(scrollView: UIScrollView) {
scrollOffset = tableView.contentOffset.y + viewHeight
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testComentName.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellComentYo", forIndexPath: indexPath) as! celdaComentYo
cell.selectionStyle = .None
cell.nomLabel.text = testComentName[indexPath.row]
return cell
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "My Title:"
}
func loadTable() {
self.tableView.reloadData()
}
}
ich denke, das Problem in scrollViewDidScroll ist, aber ich weiß nicht, ho w um den Scroll-Header zu aktivieren.
Danke!
es funktioniert perfekt!, Danke! – Andres