Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 425 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
scrollToRowAtIndexPath with UITableView does not work

#11
Heres Swift 3 version

let numberOfSections = self.tableView.numberOfSections
let numberOfRows = self.tableView.numberOfRows(inSection: numberOfSections-1)

if numberOfRows > 0 {
let indexPath = NSIndexPath.init(row: numberOfRows-1, section: numberOfSections-1)
self.tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.bottom, animated: animated)
}
Reply

#12
**SWIFT 3 VERSION of @Fox5150 answer, with an extension :**

extension UITableView {

func tableViewScrollToBottom(animated: Bool) {

DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {

let numberOfSections = self.numberOfSections
let numberOfRows = self.numberOfRows(inSection: numberOfSections-1)
if numberOfRows > 0 {
let indexPath = IndexPath(row: numberOfRows-1, section: (numberOfSections-1))
self.scrollToRow(at: indexPath, at: UITableViewScrollPosition.bottom, animated: animated)
}
}
}
}

**USAGE:**

self.tableView.tableViewScrollToBottom(animated: true)

Reply

#13
Call scrollToLastPosition() method after loading the tableview like call from viewWillAppear( ) or after table view reload when some thing changed into tableview


func scrollToLastPosition() {
if !message.isEmpty {
let indexpath = NSIndexPath(forRow: message.count - 1 , inSection: 0)
self.tableView.scrollToRowAtIndexPath(indexpath, atScrollPosition: .Bottom, animated: true)
}
}
Reply

#14
The better solution is to flip upside down the tableView so you can show new message just by
`-insertRowsAtIndexPaths:withRowAnimation:`

to do it you need first to flip your table by:

_tableView.transform = CGAffineTransformMakeScale (1,-1);

then don't forget to flip back your cells, best place to do it in -awakeFromNib by subclassing:

- (void)awakeFromNib {
[super awakeFromNib];
self.contentView.transform = CGAffineTransformMakeScale (1,-1);

//if you have accessoryView
self.accessoryView.transform = CGAffineTransformMakeScale (1,-1);
}
Reply

#15
Try reloading first before calling scroll. Very weired but works for iOS8.

tableView.reloadData()
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
Reply

#16
I have the problem with a bigger index say even 15. Only indexes till 5-6 use to work. By making "animated: false" scrollToRowAtIndexPath() worked perfectly.
Reply

#17
The solution at my problem is:

let numberOfSections = tableView.numberOfSections()
let numberOfRows = tableView.numberOfRowsInSection(numberOfSections-1)

if numberOfRows > 0 {
println(numberOfSections)
let indexPath = NSIndexPath(forRow: numberOfRows-1, inSection: (numberOfSections-1))
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: animated)
}
Reply

#18
If the keyboard is still visible you have to set the `UITableView`'s `contentInset` property to compensate for the keyboard height at the bottom of the screen. Otherwise your cell might be hidden behind the keyboard because the `UITableView` doesn't know that half of its content is hidden by it.

Or use a `UITableViewController` which handles that automatically.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through