简体   繁体   English

在iOS 8.1中,当我在UITableView处于编辑模式时单击行的删除按钮时,该行及其上方的行显示不正确

[英]In iOS 8.1, when I click on a row's delete button while UITableView is in edit mode, the row and those above it display incorrectly

I have a UITableView showing cells under different sections. 我有一个UITableView显示不同部分下的单元格。 The cells within each section can be deleted. 可以删除每个部分中的单元格。 Ie, when the UITableView is in edit mode, the cells' styles are set to UITableViewCellEditingStyleDelete. 即,当UITableView处于编辑模式时,单元格的样式设置为UITableViewCellEditingStyleDelete。 When the user clicks the delete button within a cell with this style, the Delete confirmation button shows to the right as expected. 当用户单击具有此样式的单元格中的删除按钮时,“删除确认”按钮将按预期显示在右侧。 Since updating to iOS version 8.1, the row's contents and the contents of the section header cells above it are skewed to the left. 自从更新到iOS 8.1版以来,行的内容和它上面的节标题单元格的内容都向左倾斜。

In Delete Mode, before clicking on delete button on the left hand side 在删除模式下,单击左侧的删除按钮

在单击删除按钮之前,删除模式下的屏幕截图

After clicking on delete button on the left hand side 点击左侧的删除按钮后

点击删除按钮后的屏幕截图

This was working fine up until I updated to iOS version 8.1. 这很好用,直到我更新到iOS 8.1版。 Has anyone else run into this? 有没有其他人遇到这个?

Edit: Relevant snippets of code 编辑:相关的代码片段

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return [[_store getGroceryAisles] itemCount];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self isCellBeingEdited:indexPath])
    {
        return UITableViewCellEditingStyleNone;
    }
    else
    {
        return (_editIsDeleting) ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleInsert ; 
    }
 }
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
     NSArray* aisles = [[[self store] getGroceryAisles] list];
     HGGSGroceryAisle* aisle = [aisles objectAtIndex:section];
     return [[aisle grocerySections ] count];
 }
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     NSString *cellIdentifier = @"GrocerySectionCell";
     HGGSGrocerySection * grocerySection;

     grocerySection = [self grocerySectionAt:indexPath inTableView:tableView];
     if ([self isCellBeingEdited:indexPath])
     {
         if ([tableView isEditing])
             cellIdentifier = EDIT_CELL_ID;
         else
         {
             _ipBeingEdited = nil;
         }
        }

        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if ([cellIdentifier  isEqualToString:EDIT_CELL_ID])
        {
              NSString* name = [grocerySection name];
              // skipping other code to set up cell when editing cell....
              _cellBeingEdited = cell;
        }
        else
        {
              [[cell textLabel] setText:[grocerySection name]];

         }
         return cell;
      }

      -(UITableViewCell*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
      {    
          NSString *cellIdentifier;
          HGGSGroceryAisle* aisle;

          if ((tableView == [self tableView]) && (section == 0))
          {
              cellIdentifier = (tableView.isEditing)  ? @"EditngAislesConfigHeaderCell" : @"AislesConfigHeaderCell";
          }
          else
              cellIdentifier =  @"GrocerySectionHeaderCell";

          UITableViewCell *cell= [[self tableView] dequeueReusableCellWithIdentifier:cellIdentifier];   
          UILabel *aisleLabel = (UILabel*)[cell viewWithTag:1] ;

          NSString *aisleLabelText = [NSString stringWithFormat:@"Aisle %li",(long)[aisle number]];
          aisle = [[_store getGroceryAisles] itemAt:section];
          [aisleLabel setText:aisleLabelText];
          [aisleLabel setAccessibilityLabel:aisleLabelText];       

          return cell;
      }

      - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
      {
          if ((_ipBeingEdited) && (_ipBeingEdited.row == indexPath.row) && (_ipBeingEdited.section == indexPath.section))
              return NO;
          else
              return YES;
      }

      - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
      {
          return NO;
      }
      - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
      {
         if (editingStyle == UITableViewCellEditingStyleDelete)
         {
             // Delete the row from the data source
             [_store removeGrocerySection:[self grocerySectionAt:indexPath inTableView:tableView] fromAisle:[self aisleAt:indexPath inTableView:tableView]];
             [tableView reloadData];
          }   
     }

in the method: 在方法中:

-(UITableViewCell*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    ...
    return cell;
}

Instead of return the cell object, try to return the contentView. 而不是返回单元格对象,尝试返回contentView。

-(UITableViewCell*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    ...
    return cell.contentView;
}

I have solved my problem in that way. 我以这种方式解决了我的问题。 I am using Swift, but it seems the same way in Objective-C. 我正在使用Swift,但在Objective-C中它似乎是一样的。

My problem was that I as returning a UITableViewCell from "viewForHeaderInSection". 我的问题是我从“viewForHeaderInSection”返回一个UITableViewCell。 The behavior was corrected by returning the contentView of the cell instead. 通过返回单元格的contentView来纠正行为。

Interesting that the original code worked fine in iOS 7. I don't know if it was working by design or by accident. 有趣的是,原始代码在iOS 7中运行良好。我不知道它是按设计还是偶然工作。 Ie, since UITableCellView inherits from UIView, I am not certain that returning a UITableViewCell is really incorrect. 即,由于UITableCellView继承自UIView,我不确定返回UITableViewCell是否真的不正确。 As an fyi (in case it helps someone else looking to implement custom headers and footers), I got the idea of returning the contentView property from How to Implement Custom Table View Section Headers and Footers with Storyboard . 作为一个fyi(如果它帮助其他人寻求实现自定义页眉和页脚),我想到了如何使用Storyboard如何实现自定义表视图部分页眉和页脚返回contentView属性。

Try this 尝试这个

First Edit button add to NavigationBar in Top of ViewControl First Edit按钮添加到ViewControl顶部的NavigationBar

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
    [imagearray removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];


}
    else if(editingStyle == UITableViewCellEditingStyleInsert)
    {

    }
}

I hope it's Work for you 我希望它对你有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM