2016-04-13 4 views
0

при условии, что ни один из ответов здесь iOS UITableView Scroll to bottom of section работают корректно, когда высота Tableview строки не меняется, я должен снова спросить: как я надежно перейдите к нижней части Таблица? Значение: нижняя часть содержимого таблицы выстроились с нижней части представления таблицыUITableView scrolltobottom, который работает в случае, если RowHeight == UITableViewAutomaticDimension

это

extension UITableView 
{ 
func scrollToBottom(animated: Bool = true) 
{ 
    layoutSubviews() // if rowHeight UITableViewAutomaticDimension you have to force layout to get semi-correct content size height 
    let csh = contentSize.height 
    let fsh = bounds.size.height 
    if csh > fsh { 
     let offset = csh - fsh 
     setContentOffset(CGPointMake(0, offset), animated: animated) 
    } 
} 
} 

почти работает, но до сих пор underscrolls примерно 150-200 пикс как на 9.3.1 и 8.4.1

Пусть смещение = CSH

и благополучно overscrolls показывая на верхней части его содержание underscrolled по в случае пусть смещение = CSH - фсх с последующим еси пробельных наполненной пустоты

, учитывая, что «отскакивает вертикально» проверяется на Tableview в раскадровке он правильно подпрыгивает в последнем случае данной малейшая провокация прикосновения пользователя ;-)

это unioslike сложный и очень андроид.

это должно было быть просто, не так ли? правильно?

+0

Что произойдет, если вы вызовете scrollToRowAtIndexPath и спросите свой источник данных для последнего индекса? – Dare

ответ

0

scrollToRowAtIndexPath действительно работает с ячейкой динамической высоты. Вот пример:

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 

    @IBOutlet weak var tableView: UITableView! 
    override func viewDidLoad() { 
     super.viewDidLoad() 
     tableView.rowHeight = UITableViewAutomaticDimension 
     tableView.estimatedRowHeight = 100 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 20 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = UITableViewCell() 
     cell.textLabel?.numberOfLines = 0 
     cell.textLabel?.lineBreakMode = .ByWordWrapping 
     cell.textLabel?.text = [String](count: indexPath.row, repeatedValue: "Hello").joinWithSeparator(" ") 
     return cell 
    } 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     let lastRow = tableView.numberOfRowsInSection(0) 

     tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: lastRow - 1, inSection: 0), atScrollPosition: .Bottom, animated: true) 
    } 
} 
+0

не совсем, он работал на 9.3.1, но не смог прокрутить весь путь вниз на 8.4.1 –

Смежные вопросы