apollo9 apollo9 - 1 year ago 56
iOS Question

how many time heightForRowAtIndexPath being called before view Presentation? Objective-c

I'm developing an

app, and I have found this problem, why when I present
, the method
it's called more than one time for each row?

For Example if I have ten row, the method will be calls 30 times.

Answer Source

Unlike numberOfSectionsInTableView which is called once, and numberOfRowsInSection, which is called once per section, heightForRowAtIndexPath is called for each row. Generally, the component needs to find out how many rows it needs to create (which translates to how many row cells it needs to allocate) so it keeps calling heightForRowAtIndexPath until the total height is sufficient to cover the area of the screen, plus a few more rows for the scroll.

In your situation it looks like the screen is high enough to fit some 30 rows of your table; hence, you get thirty calls to heightForRowAtIndexPath. These calls will be followed by roughly as many calls to cellForRowAtIndexPath.