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

      1. <small id='U5wyS'></small><noframes id='U5wyS'>

        向 NSFetchedResultsController 管理的 UITableView 添加额外

        时间:2023-05-30
          <bdo id='oBAVW'></bdo><ul id='oBAVW'></ul>
          <legend id='oBAVW'><style id='oBAVW'><dir id='oBAVW'><q id='oBAVW'></q></dir></style></legend>
          1. <i id='oBAVW'><tr id='oBAVW'><dt id='oBAVW'><q id='oBAVW'><span id='oBAVW'><b id='oBAVW'><form id='oBAVW'><ins id='oBAVW'></ins><ul id='oBAVW'></ul><sub id='oBAVW'></sub></form><legend id='oBAVW'></legend><bdo id='oBAVW'><pre id='oBAVW'><center id='oBAVW'></center></pre></bdo></b><th id='oBAVW'></th></span></q></dt></tr></i><div id='oBAVW'><tfoot id='oBAVW'></tfoot><dl id='oBAVW'><fieldset id='oBAVW'></fieldset></dl></div>

              • <small id='oBAVW'></small><noframes id='oBAVW'>

                  <tfoot id='oBAVW'></tfoot>

                    <tbody id='oBAVW'></tbody>
                  本文介绍了向 NSFetchedResultsController 管理的 UITableView 添加额外的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在我的应用程序中为表格使用 UITableViewController,并且我添加了一个 NSFetchedResultsController 来提供要在表格中显示的数据(设置 self 作为它的委托).

                  I'm using a UITableViewController for a table in my app, and I've added an NSFetchedResultsController to provide the data to show in the table (setting self as it's delegate).

                  但是我想添加一个唯一的单元格作为表格的最后一个单元格,与 NSFetchedResultsController 的谓词产生的项目无关,我希望这个单元格始终位于底部桌子.

                  However I would like to add a unique cell as the last cell of the table, unrelated to the items produced by the NSFetchedResultsController's predicate, I want this cell to always be at the bottom of the table.

                  我已经尝试在表格视图数据源中简单地为这些方法添加 1:

                  I've tried simply added 1 to these methods in the table view data source:

                  - (NSUInteger)numberOfSectionsInTableView:(UITableView *)sender
                  {
                      return [[self.fetchedResultsController sections] count] + 1;
                  }
                  - (NSUInteger)tableView:(UITableView *)sender numberOfRowsInSection:(NSUInteger)section
                  {
                      return [[[self.fetchedResultsController sections] objectAtIndex:section] numberOfObjects] + 1;
                  }
                  

                  然后捕获这样生成额外行的情况(该表只有 1 个部分):

                  And then catching the case where this extra row is being generated like so (the table only has 1 section):

                  - (UITableViewCell *)tableView:(UITableView *)sender
                           cellForRowAtIndexPath:(NSIndexPath *)indexPath
                  {
                      if (indexPath.row == [self.fetchedResultsController.fetchedObjects count]) {
                          //Generate the last cell in  table.
                      } else {
                          //Generate the rest of the cells like normal.
                      }
                      return nil; //To keep the compiler happy.
                  }
                  

                  这会检查索引是否是最后一个单元格并适当地处理它.

                  This checks to see if the index is the last cell and deals with it appropriately.

                  但是我在运行时仍然收到以下错误:

                  However I am still getting the following error at runtime:

                  *** Terminating app due to uncaught exception 'NSRangeException', 
                  reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
                  

                  知道是什么原因造成的吗?或者有没有更好的方法向由 NSFetchedResultsController 控制的表视图添加额外的行?

                  Any idea what's causing this? Or is there a better way of adding an extra row to a table view controlled by an NSFetchedResultsController?

                  推荐答案

                  如果您实现文档中指示的所有数据源方法(更新等),则获取的结果控制器与 tableview 紧密相关.它会变得非常混乱和hacky.

                  The fetched results controller is pretty tightly tied to the tableview, if you implement all the datasource methods as indicated in the documentation (the updates and so on). It will get pretty messy and hacky.

                  您的额外行"可以改为表格的页脚视图吗?这将永远在底部.让它看起来像一个单元格不会做太多的工作,尽管从它的外观来看,无论如何你希望它看起来与其他单元格不同.

                  Could your "extra row" be the footer view of the table instead? This will always be at the bottom. It wouldn't be too much work to make it look like a cell, though from the look of it you want it to look different to the other cells anyway.

                  这篇关于向 NSFetchedResultsController 管理的 UITableView 添加额外的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Objective-C 字符串(yyyy-mm-dd)到 NSDate 下一篇:iOS5 中 Unicode 字符的绘制方式不同

                  相关文章

                  最新文章

                1. <i id='LVlkL'><tr id='LVlkL'><dt id='LVlkL'><q id='LVlkL'><span id='LVlkL'><b id='LVlkL'><form id='LVlkL'><ins id='LVlkL'></ins><ul id='LVlkL'></ul><sub id='LVlkL'></sub></form><legend id='LVlkL'></legend><bdo id='LVlkL'><pre id='LVlkL'><center id='LVlkL'></center></pre></bdo></b><th id='LVlkL'></th></span></q></dt></tr></i><div id='LVlkL'><tfoot id='LVlkL'></tfoot><dl id='LVlkL'><fieldset id='LVlkL'></fieldset></dl></div>
                  <tfoot id='LVlkL'></tfoot>
                2. <small id='LVlkL'></small><noframes id='LVlkL'>

                  <legend id='LVlkL'><style id='LVlkL'><dir id='LVlkL'><q id='LVlkL'></q></dir></style></legend>

                      • <bdo id='LVlkL'></bdo><ul id='LVlkL'></ul>