Last active
October 6, 2017 12:48
-
-
Save Th3nion/1744832760de7f9fcc6bb0b775e5af1f to your computer and use it in GitHub Desktop.
UITableView extension wich allow to keep content view at the bottom of the cells.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UITableView+insertScroll.swift | |
// | |
// Created by mtournier on 13/09/17. | |
// NO Copyright !!! | |
// | |
import UIKit | |
extension UITableView { | |
func insertRowsWithScroll(at indexPath:IndexPath){ | |
let visiblePaths = self.indexPathsForVisibleRows | |
var bottomPath = visiblePaths?.last | |
let bRow = bottomPath?.row | |
let bSection = bottomPath?.section | |
let row = indexPath.row | |
let section = indexPath.section | |
let nextRowInSameSection = (section == bSection) && (row == (bRow! + 1)) | |
let firstRowInNextSection = ((section == (bSection! + 1)) && (row == 0)); | |
let shouldScroll = nextRowInSameSection || firstRowInNextSection; | |
self.insertRows(at: [indexPath], with: UITableViewRowAnimation.right) | |
if (shouldScroll) { | |
self.scrollToRow(at: indexPath, at: .bottom, animated: true) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment