Calling numberOfRowsInSection: from heightForRowAtIndexPath

后端 未结 1 1280
情书的邮戳
情书的邮戳 2021-02-19 15:05

Just found a very strange and unexpected behavior in the UITableView class. I need the last table cell in my section to be a different height from the other cells, so I\'m doing

相关标签:
1条回答
  • 2021-02-19 15:43

    The problem is that the UITableView is asking your datasource for data, and you are telling it the answer depends on data it may or may not have cached.

    You're misunderstanding the M-V-C layout that Apple bases its controls on. The answer to the height of a row should come from your model, NOT from a call back to the view class. This is causing the view class to ask for more information (to build its internal cache), which is starting a set of recursive calls.

    Make sure all datasource delegate methods return data from your model and don't rely on the view caching anything. If you debug any datasource based view, you'll be surprised how many times a UITableView asks for data. But that's the way Apple coded it.

    0 讨论(0)
提交回复
热议问题