Indexpath.row starts at 1 instead of 0

I ran into strance problem with uitableview. when my tabular data source / numberofrowsinsection has 3 values, cellforowatindexpath starts at 0-1 instead of 0-0. can someone help me find possible causes for this problem. even tried to print logs, but logs were shown for 0 -1 and 0 -2, but not for 0 -0. This means that it is not called for the first line ie 0 -0.

+6
source share
3 answers

tableView:cellForRowAtIndexPath: is called as necessary to display the cell; if the cell is not displayed, it is not called. If row 0 is not displayed, cell 0-0 will not be called.

+3
source

As Zaph said, tableView:cellForRowAtIndexPath: is called whenever the table wants to display a cell for a given pointer path, so if you don't get an index pointer with a row of 0, it means that you probably do what prevents this cell from showing.

My first suggestion was to examine your tableView:heightForRowAtIndexPath: method and 1) check if it will be called using the index path string 0, and 2) make sure something> 0 is returned.

The fact that you see it on iOS 8 does not necessarily mean that something native is broken, but instead may suggest that some of your logics that contribute to the above methods depend on changes in iOS 8. iOS 8 dropped the way I did the text size calculations, so maybe something less obvious, as a result, returns a height of no higher than 0.

+3
source

You can first check the number of sections and the number of rows. If the line number of the section returned is 0, this section will not be called.

0
source

Source: https://habr.com/ru/post/977022/


All Articles