TableView the invocation time of the proxy method (mostly Heightforrowatindexpath and Cellforrowatindexpath call times)

Source: Internet
Author: User

Recently, a demo is involved in classifying and forming different types of cells in Cellforrowatindexpath according to the data, There is a judgment (done in viewdidload) and formation (done in Cellforrowatindexpath) two stages. This time I have a question, viewdidload and cellforrowatindexpath in what order, so in a few functions to record the printing process:

 --Geneva-Geneva  -: -:20.970whentocom[9790:1381585] -[Contactertableviewcontroller Viewdidload] --Geneva-Geneva  -: -:21.167whentocom[9790:1381585] -[Contactertableviewcontroller viewwillappear:] --Geneva-Geneva  -: -:21.171whentocom[9790:1381585] -[Contactertableviewcontroller Numberofsectionsintableview:] --Geneva-Geneva  -: -:21.172whentocom[9790:1381585] -[Contactertableviewcontroller tableview:numberofrowsinsection:] --Geneva-Geneva  -: -:21.173whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:heightforrowatindexpath:] --Geneva-Geneva  -: -:21.174whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:heightforrowatindexpath:] --Geneva-Geneva  -: -:21.177whentocom[9790:1381585] -[Contactertableviewcontroller viewdidappear:] --Geneva-Geneva  -: -:21.181whentocom[9790:1381585] -[Contactertableviewcontroller Numberofsectionsintableview:] --Geneva-Geneva  -: -:21.182whentocom[9790:1381585] -[Contactertableviewcontroller tableview:numberofrowsinsection:] --Geneva-Geneva  -: -:21.195whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:heightforrowatindexpath:] --Geneva-Geneva  -: -:21.197whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:heightforrowatindexpath:] --Geneva-Geneva  -: -:21.199whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:cellforrowatindexpath:] --Geneva-Geneva  -: -:21.206whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:heightforrowatindexpath:] --Geneva-Geneva  -: -:21.208whentocom[9790:1381585] -[Contactertableviewcontroller Tableview:cellforrowatindexpath:] --Geneva-Geneva  -: -:21.211whentocom[9790:1381585]-[contactertableviewcontroller Tableview:heightforrowatindexpath:]

It can be found that the cellforrowatindexpath of TableView is not executed until after viewdidappear.

However, there is a second question, I have two data in this table, but why the Heightforrowatindexpath method was executed 6 times, and only the last two times is to interact with Cellforrowatindexpath, This means that the cell is actually drawn. Search on the internet for half a day inconclusive, referring to a number of similar questions, guess is the two calls between Viewwillappear and viewdidappear are used to estimate the height of tableview, Following viewdidappear two times is the actual calculation of tableview height, the last two times is to draw the cell.

By the way PS the difference in the life cycle of the view (original link):

When a view controller is created and displayed on the screen. Order of execution of code

1, Alloc create objects, allocate space

2. Init (Initwithnibname) initializes the object, initializes the data

3, Loadview from the nib load view, usually this step does not need to interfere. Unless you're not using the Xib file to create a view

4, Viewdidload loading complete, can be customized data and dynamic creation of other controls

5, Viewwillappear View will appear before the screen, the view will be displayed on the screen immediately

6, Viewdidappear view has been rendered on the screen completed

When a view is removed from the screen and the execution order is destroyed, the order is almost the opposite of the above

1. Viewwilldisappear view will be removed from the screen before execution

2, Viewdiddisappear view has been removed from the screen, the user can not see this view

3. Dealloc view is destroyed, you need to release the objects you created in Init and viewdidload

TableView the invocation time of the proxy method (mostly Heightforrowatindexpath and Cellforrowatindexpath call times)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.