I have a table with a custom header that I dragged into it. The table view also has a prototype cell. When on a device the table bounces back before reaching the bottom of the content. This problem does not happen without the header. It looks like the table view is able to scroll through about the same amount of content if the header is there or not there (with the header it can scroll through the header and about 2 prototype cells, and without the header it can scroll through about 5 prototype cells). I attached a youtube link because the problem is kind of difficult to describe.
https://www.youtube.com/watch?v=4xaOjcUnFVk&feature=youtu.be
My tableviewdelegate functions
extension ProfileViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return statuses.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let status = statuses[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileStatusCell") as! ProfileStatusCell
cell.setup(with: status)
self.tableView.frame.size = tableView.contentSize
return cell
}
}
My ViewController class
class ProfileViewController: UIViewController{
var uid: String? //Is for the current user
var statuses = [Status]()
var avatar: Avatar?{
didSet{
avatarButton.setImage( AvatarImage.newAvatar(values: avatar!.values).image!.withRenderingMode(.alwaysOriginal), for: .normal)
}
}
@IBOutlet weak var tableHeader: UIView!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var nameLabel: UITextField!
@IBOutlet weak var bio: UITextView!
@IBOutlet weak var avatarButton: UIButton! //Must set the image from another viewController
@IBOutlet weak var followButton: UIButton!
@IBOutlet weak var messageButton: UIButton!
@IBOutlet weak var blockButton: UIButton!
@IBOutlet weak var reportButton: UIButton!
@IBOutlet weak var logoutButton: UIButton!
@IBAction func logout(_ sender: UIButton) {
FBCoreUser(currentUser.uid!).changeVisibility(to: Visibility.invisible)
FBUser.signOut(completion: {(_) in return})
//let start = self.presentingViewController as! Start
self.dismiss(animated: true, completion: nil)
}
@IBAction func blockUser(_ sender: UIButton) {
}
@IBAction func reportUser(_ sender: UIButton) {
}
override func viewDidLoad(){
tableView.tableHeaderView = tableHeader
if uid == nil{ //If it's the page for the current user
self.avatar = currentUser.avatar
if currentUser.name == nil{
FBProfileData(currentUser.uid!).get(dataFor: {(pData) in
let data = pData as! ProfileData
self.fillProfile(name: data.uName, bio: data.bio, statuses: data.statuses!)
})
}else{
fillProfile(name: currentUser.name!, bio: currentUser.bio!, statuses: currentUser.statuses!)
}
}else{
self.logoutButton.isHidden = true
self.blockButton.isHidden = false
self.followButton.isHidden = false
self.reportButton.isHidden = false
FBProfileData(uid!).get(dataFor: {(pData) in
let data = pData as! ProfileData
self.fillProfile(name: data.uName, bio: data.bio, statuses: data.statuses!)
})
}
}
func fillProfile(name: String, bio: String, statuses: [Status]){
self.nameLabel.text = name
self.bio.text = bio
self.statuses = statuses
tableView.reloadData()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "avatarBuilder"{
if let vc = segue.destination as? AvatarBuilder {
vc.avatar = avatar
}
}
}
}
extension ProfileViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return statuses.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let status = statuses[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "ProfileStatusCell") as! ProfileStatusCell
cell.setup(with: status)
self.tableView.frame.size = tableView.contentSize
return cell
}
}
extension ProfileViewController: UITextViewDelegate, UITextFieldDelegate{
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if text == "\n" {
textView.resignFirstResponder()
//self.view.endEditing()
}
return true
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
self.view.endEditing(true)
return false
}
/* Takes the keyboard of a text field off the screen */
@objc func closeKeyboard() {
self.view.endEditing(true)
}
/* Closes the keyboard when somewhere else on the screen is touched */
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
closeKeyboard()
}
}