Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect last visible cell in UITableView

I am new in iOS development and currently working on UITableView. I want to find last visible cells on the screen of device and cells that are at the bottom of the screen must be of blue color, which should fade to green as the cell is scrolled to the top of the screen.

I have gone through these links

Link1 Link2

But could not get success. Can anyone please provide idea how to detect last cells & cell fade animation?

like image 586
Nupur Rawat Avatar asked Jan 21 '26 12:01

Nupur Rawat


2 Answers

Get last visible cell:

if let lastCell = tableView.visibleCells.last {
    // do something with lastCell
}
like image 194
shallowThought Avatar answered Jan 24 '26 02:01

shallowThought


In Swift 3.0, you can used this tableview method.

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
    let intTotalrow = tableView.numberOfRows(inSection:indexPath.section)//first get total rows in that section by current indexPath.           
    //get last last row of tablview
    if indexPath.row == intTotalrow - 1{

        // call for last display 
    }
}
like image 26
Jaydip Avatar answered Jan 24 '26 03:01

Jaydip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!