apollo9 apollo9 - 2 months ago 12
iOS Question

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

I'm developing an

iPad
app, and I have found this problem, why when I present
tableView
, the method
heightForRowAtIndexPath
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

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.