corocraft
corocraft

Reputation: 150

how could i detect in a UITableView, what are the cells deployed in my phone screen

I am trying to figure out how to detect which UITableViewCell in a UITableView are deployed in my phone screen.

For example: My numberOfRowsInSection are 20 but i see just 3 of them on the phone screen. I want to know how do determine which three are shown?

In my case, I need to send only the publicity that the users viewed in your phone screen and not the 20 rows loaded in the UITableView.

Thanks!

Upvotes: 0

Views: 178

Answers (4)

7vikram7
7vikram7

Reputation: 2824

    let visibleIndexPaths = tableview.indexPathsForVisibleRows

    var visibleCellsArray: [UITableViewCell] = []

    for currentIndextPath in visibleIndexPaths! {
       //  You now have visible cells in visibleCellsArray
        visibleCellsArray.append(tableview.cellForRowAtIndexPath(currentIndextPath)!)
    }

You now have visible cells in visibleCellsArray.

Upvotes: 1

Geoff S
Geoff S

Reputation: 175

To determine the NSIndexPath values for the rows displayed on the screen, consider the answer to this related SO question.

Specifically, to get an array of the visible table cells, use:

self.tableView.indexPathsForVisibleRows

Upvotes: 0

let visibleIndexPaths = self.tableView.indexPathsForVisibleRows() as? [NSIndexPath]

This gives the array of indexPath that the cell are in visible..

i hope this will help you...

Upvotes: 0

Saheb Singh
Saheb Singh

Reputation: 557

Your cellForRowAtIndexPath method calls for the number of visible cells only.IF YOU DEQUEUE THEM. If you want to do something based on your visible cell, either put some logic in cellForRowAtIndexPath or use indexPathsForVisibleRows which will give you back an array of visible cells and you can go on with your logic.

Upvotes: 0

Related Questions