<bdo id='uKp9C'></bdo><ul id='uKp9C'></ul>

  • <i id='uKp9C'><tr id='uKp9C'><dt id='uKp9C'><q id='uKp9C'><span id='uKp9C'><b id='uKp9C'><form id='uKp9C'><ins id='uKp9C'></ins><ul id='uKp9C'></ul><sub id='uKp9C'></sub></form><legend id='uKp9C'></legend><bdo id='uKp9C'><pre id='uKp9C'><center id='uKp9C'></center></pre></bdo></b><th id='uKp9C'></th></span></q></dt></tr></i><div id='uKp9C'><tfoot id='uKp9C'></tfoot><dl id='uKp9C'><fieldset id='uKp9C'></fieldset></dl></div>

    <small id='uKp9C'></small><noframes id='uKp9C'>

        <legend id='uKp9C'><style id='uKp9C'><dir id='uKp9C'><q id='uKp9C'></q></dir></style></legend>
      1. <tfoot id='uKp9C'></tfoot>
      2. UITableView 委托方法调用了两次

        时间:2023-07-28

          <tbody id='ppe2n'></tbody>
        • <legend id='ppe2n'><style id='ppe2n'><dir id='ppe2n'><q id='ppe2n'></q></dir></style></legend>
          <tfoot id='ppe2n'></tfoot>

                <bdo id='ppe2n'></bdo><ul id='ppe2n'></ul>

                <small id='ppe2n'></small><noframes id='ppe2n'>

                <i id='ppe2n'><tr id='ppe2n'><dt id='ppe2n'><q id='ppe2n'><span id='ppe2n'><b id='ppe2n'><form id='ppe2n'><ins id='ppe2n'></ins><ul id='ppe2n'></ul><sub id='ppe2n'></sub></form><legend id='ppe2n'></legend><bdo id='ppe2n'><pre id='ppe2n'><center id='ppe2n'></center></pre></bdo></b><th id='ppe2n'></th></span></q></dt></tr></i><div id='ppe2n'><tfoot id='ppe2n'></tfoot><dl id='ppe2n'><fieldset id='ppe2n'></fieldset></dl></div>

                  本文介绍了UITableView 委托方法调用了两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  今天我的问题是关于 UITableViewController-s特别是我注意到数据源委托方法

                  Today my question is about UITableViewController-s In particular I have noticed that the datasource delegate method

                  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
                  

                  被调用了两次(即使我只是创建了一个基于导航的应用程序并且没有添加一行代码......以及添加一个 NSLog 来跟踪它).现在,由于在我的应用程序中,我需要根据文件系统中的文档来确定节的数量,因此我需要调用一些方法来做到这一点.我已经把这些方法放在了上面提到的方法中,所以它们会被调用两次,这是我不需要的.问题是为什么要调用两次,我可以调用一次吗?我希望在官方文档中没有明确说明(这意味着我根本没有阅读它:)).顺便说一句,我可以看到其他人发布类似的问题,但我找不到完全令人满意的答案.谢谢.

                  is called twice (even if for instance I just create a navigation based application and without adding a line of code.. well adding an NSLog to track it). Now, since in my application I need to determine the number of sections basing the choice on the documents in the file system, I need to call some methods to do so. I have put these methods in the above mentioned method, so they will be called twice, which is something I don't need. The questions are why is it called twice, can I have it called once? I hope that in the official documentation this is not clearly stated (which would mean that I didn't read it at all :) ). By the way I could see others posting similar questions, but I couldn't find a fully satisfying answer. Thank you.

                  推荐答案

                  我遇到了同样的问题,只是调用了 numberOfRowsInSection:我收到的每个呼叫的答案都放在堆栈跟踪中.

                  I was experiencing the same problem, only with the call to numberOfRowsInSection: The answered laid in the stack trace for each call I received.

                  1. 第一次调用是由于我在 viewcontroller 的 viewDidLoad: 中所做的表头视图发生了变化.

                  1. The first call was due to a change in the table header view I was making in the viewDidLoad: of my viewcontroller.

                  thumbView.tableHeaderView = nil;
                  thumbView.tableFooterView = nil;
                  

                  这导致了对 _updateContentSize: 的内部调用,该调用调用了 heightForTable:,最终调用了 numberOfRowsInSection:.这是我触发的,可以通过不执行上述代码轻松避免:)

                  This resulted in internal call to _updateContentSize: which called heightForTable: which eventually called numberOfRowsInSection:. This was something I triggered, and could be easily avoided by not doing the above code :)

                  第二次调用是为了重新加载数据的合法调用.这是由某处的布局事件触发的,您很可能无法跳过它.

                  The second call was the legitimate one in order to reloadData. This is triggered by a layout event somewhere and most likely you can't skip it.

                  我相信你可以观察到 numberOfSections: 方法类似的东西

                  I'm sure you can observe something similar for the numberOfSections: method

                  所以,我的结论是,由于 UITableView 的实现,在很多情况下某些委托方法将被调用两次或更多次,因为表视图必须刷新某些内容.我尝试围绕这个错误/功能/等设计我的代码.

                  So, my conclusion is that due to the the implementation of UITableView there are many situations where certain delegate methods will get called twice or more because the table view has to refresh something. I try to design my code around this bug/feature/etc.

                  希望对你有帮助

                  这篇关于UITableView 委托方法调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Objective C 中调用另一个类的方法 下一篇:简单的代表示例?

                  相关文章

                    <tfoot id='ZWNMZ'></tfoot>

                      <small id='ZWNMZ'></small><noframes id='ZWNMZ'>

                      <legend id='ZWNMZ'><style id='ZWNMZ'><dir id='ZWNMZ'><q id='ZWNMZ'></q></dir></style></legend>
                        <bdo id='ZWNMZ'></bdo><ul id='ZWNMZ'></ul>
                    1. <i id='ZWNMZ'><tr id='ZWNMZ'><dt id='ZWNMZ'><q id='ZWNMZ'><span id='ZWNMZ'><b id='ZWNMZ'><form id='ZWNMZ'><ins id='ZWNMZ'></ins><ul id='ZWNMZ'></ul><sub id='ZWNMZ'></sub></form><legend id='ZWNMZ'></legend><bdo id='ZWNMZ'><pre id='ZWNMZ'><center id='ZWNMZ'></center></pre></bdo></b><th id='ZWNMZ'></th></span></q></dt></tr></i><div id='ZWNMZ'><tfoot id='ZWNMZ'></tfoot><dl id='ZWNMZ'><fieldset id='ZWNMZ'></fieldset></dl></div>