• <legend id='Z8BtJ'><style id='Z8BtJ'><dir id='Z8BtJ'><q id='Z8BtJ'></q></dir></style></legend>
    • <bdo id='Z8BtJ'></bdo><ul id='Z8BtJ'></ul>

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

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

        编辑同时删除 UITableView 中的多行

        Edit amp; delete multiple rows in UITableView simultaneously(编辑同时删除 UITableView 中的多行)
      2. <small id='9wJIb'></small><noframes id='9wJIb'>

        <tfoot id='9wJIb'></tfoot>

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

              <tbody id='9wJIb'></tbody>
            <legend id='9wJIb'><style id='9wJIb'><dir id='9wJIb'><q id='9wJIb'></q></dir></style></legend>
              <bdo id='9wJIb'></bdo><ul id='9wJIb'></ul>

                  本文介绍了编辑同时删除 UITableView 中的多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的应用程序中,我需要删除表格中的多行,编辑表格并在表格旁边获得一个复选框.选中后,表格单元格将被删除.它就像 iPhone 消息应用程序.我该怎么做,请帮助我.

                  In my app I need to delete multiple rows in a table, edit the table and get a check box beside the table. When checked then the table cells are deleted. It is like the iPhone message app. How can I do this, please help me.

                  推荐答案

                  如果我正确理解你的问题,你本质上是想以某种方式标记 UITableViewCells(a复选标记);然后,当用户点击主删除"按钮时,所有 标记 UITableViewCell 连同其对应的数据源对象一起从 UITableView 中删除.

                  If I understand your question correctly, you essentially want to mark UITableViewCells in some way (a checkmark); then, when the user taps a master "Delete" button, all marked UITableViewCells are deleted from the UITableView along with their corresponding data source objects.

                  要实现 checkmark 部分,您可以考虑在 UITableViewCellAccessoryCheckmarkUITableViewCellAccessoryNone 之间切换 UITableViewCell附件 属性.在以下 UITableViewController 委托方法中处理触摸:

                  To implement the checkmark portion, you might consider toggling between UITableViewCellAccessoryCheckmark and UITableViewCellAccessoryNone for the UITableViewCell's accessory property. Handle touches in the following UITableViewController delegate method:

                  - (void)tableView:(UITableView *)tableView
                    didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
                  
                      UITableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];
                      if (c.accessoryType == UITableViewCellAccessoryCheckmark) {
                          [c setAccessoryType:UITableViewCellAccessoryNone];
                      }
                      //else do the opposite
                  
                  }
                  

                  你也可以看看这篇文章如果您想要更复杂的 复选标记,请考虑自定义 UITableViewCell.

                  You might also look at this post regarding custom UITableViewCells if you're wanting a more complex checkmark.

                  您可以通过两种方式设置主删除"按钮:

                  You can set up a master "Delete" button two ways:

                  • IB 方法
                  • 程序化方法

                  在任何一种情况下,最终都必须在按下主删除"按钮时调用一个方法.该方法只需要遍历 UITableView 中的 UITableViewCells 并确定标记了哪些.如果标记,请删除它们.假设只有一个部分:

                  In either case, eventually a method must be called when the master "Delete" button is pressed. That method just needs to loop through the UITableViewCells in the UITableView and determined which ones are marked. If marked, delete them. Assuming just one section:

                  NSMutableArray *cellIndicesToBeDeleted = [[NSMutableArray alloc] init];
                  for (int i = 0; i < [tableView numberOfRowsInSection:0]; i++) {
                      NSIndexPath *p = [NSIndexPath indexPathWithIndex:i];
                      if ([[tableView cellForRowAtIndexPath:p] accessoryType] == 
                          UITableViewCellAccessoryCheckmark) {
                          [cellIndicesToBeDeleted addObject:p];
                          /*
                              perform deletion on data source
                              object here with i as the index
                              for whatever array-like structure
                              you're using to house the data 
                              objects behind your UITableViewCells
                          */
                      }
                  }
                  [tableView deleteRowsAtIndexPaths:cellIndicesToBeDeleted
                                   withRowAnimation:UITableViewRowAnimationLeft];
                  [cellIndicesToBeDeleted release];
                  

                  假设编辑"是指删除单个UITableViewCell"或移动单个UITableViewCell",您可以在UITableViewController 中实现以下方法:

                  Assuming by "edit" you mean "delete a single UITableViewCell" or "move a single UITableViewCell," you can implement the following methods in the UITableViewController:

                  - (void)viewDidLoad {
                      [super viewDidLoad];
                  
                      // This line gives you the Edit button that automatically comes with a UITableView
                      // You'll need to make sure you are showing the UINavigationBar for this button to appear
                      // Of course, you could use other buttons/@selectors to handle this too
                      self.navigationItem.rightBarButtonItem = self.editButtonItem;
                  
                  }
                  
                  // Override to support conditional editing of the table view.
                  - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
                      // Return NO if you do not want the specified item to be editable.
                      return YES;
                  }
                  
                  - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
                      return YES;
                  }
                  
                  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
                  
                      if (editingStyle == UITableViewCellEditingStyleDelete) {
                          //perform similar delete action as above but for one cell
                      }   
                  }
                  
                  - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
                      //handle movement of UITableViewCells here
                      //UITableView cells don't just swap places; one moves directly to an index, others shift by 1 position. 
                  }
                  

                  这篇关于编辑同时删除 UITableView 中的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  EAAccessory/EASession teardown during background(EAAccessory/EASession 在后台拆除)
                  Getting an NSArray of a single attribute from an NSArray(从 NSArray 获取单个属性的 NSArray)
                  ImageIO: lt;ERRORgt; JPEG Corrupt JPEG data: premature end of data segment iphone - how to catch this?(ImageIO:lt;错误gt;JPEG 损坏的 JPEG 数据:iphone 数据段过早结束 - 如何捕捉到这个?)
                  How to get indexPath.row of tableView which is currently being displayed?(如何获取当前正在显示的 tableView 的 indexPath.row?)
                  Xcode iOS organizer submit to app store yields quot;The archive is invalidquot; error(Xcode iOS 管理器提交到应用商店产生“存档无效;错误)
                  MFMessageComposeViewController alloc returns nil(MFMessageComposeViewController alloc 返回 nil)

                    <tbody id='7SMSG'></tbody>

                  <small id='7SMSG'></small><noframes id='7SMSG'>

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