滑动删除TableView中的单元格在iOS8中不起作用?

时间:2014-10-30 06:00:36

标签: uitableview ios8

我实现了“刷卡以删除TableView中的单元格”,它在iOS 7中工作正常,但相同的代码不适用于iOS 8. iOS 8中是否有任何更改?

在刷完单元格后,我在iOS 8的“Groups”部分看不到任何内容,而在iOS 7中,我看到一个删除按钮。

enter image description here

以下是我正在使用的代码:

 - (void)swipeableTableViewCell:(SWTableViewCell *)cell scrollingToState:  (SWCellState)state
  {
    switch (state) {
    case 0:
        NSLog(@"utility buttons closed");
        [customDropDown hideDropDown:dropDownFrame];
        [customDropDown removeFromSuperview];
        customDropDown = nil;
        break;
    case 1:
        NSLog(@"left utility buttons open");
        break;
    case 2:
        NSLog(@"right utility buttons open");
        break;
    default:
        break;
  }
}

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
  switch (index)
    {
    case 0:
    {
        if (cell.rightUtilityButtons.count == 1)
        {
            NSArray * arr = [[NSArray alloc] init];
            arr = [NSArray arrayWithArray:[self.groupsInfoDict allKeys]];

            if(customDropDown == nil)
            {
                indexPathForSelectedcontact = [self.groupListTableView indexPathForCell:cell];
                CGRect frame = [self.groupListTableView rectForRowAtIndexPath:indexPathForSelectedcontact];
                CGRect animatedViewFrame = [self.view convertRect:frame fromView:self.groupListTableView];
                CGFloat height =  self.view.frame.size.height-(animatedViewFrame.origin.y+44);
                NSString* direction;
                if (height<88)
                {
                    direction = @"up";
                    CGFloat noOfRowHeight = [arr count]*40;

                    if (noOfRowHeight <animatedViewFrame.origin.y)
                    {
                        height = noOfRowHeight;
                    }
                    else
                    {
                        height = animatedViewFrame.origin.y;
                    }
                }
                else
                {
                    direction = @"down";

                    CGFloat noOfRowHeight = [arr count]*40;

                    if (noOfRowHeight <height)
                    {
                        height = noOfRowHeight;
                    }

                }
                dropDownFrame = CGRectMake(animatedViewFrame.origin.x, animatedViewFrame.origin.y, 160,height);
                customDropDown = [[CustomDropDown alloc]showDropDown:dropDownFrame arrayOfData:arr ArrayOfimages:nil inDirection:direction onView:self.view];
                customDropDown.delegate = self;
            }
            else
            {
                [customDropDown hideDropDown:dropDownFrame];
                [customDropDown removeFromSuperview];
                dropDownFrame = CGRectZero;
                customDropDown = nil;
            }
        }
        else
        {

            NSIndexPath* indexpath = [self.groupListTableView indexPathForCell:cell];
            NSArray* arrayOfKeys = (NSArray *)self.groupsInfoDict.allKeys;
            NSArray *sortedValues = [arrayOfKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
             groupTitleSelectedForRename = [sortedValues objectAtIndex:indexpath.row];

            UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Events" bundle:nil];
            AddANewGroupViewController *addANewGroupViewController = [storyboard instantiateViewControllerWithIdentifier:@"AddANewGroupViewController"];
            addANewGroupViewController.screenType = kScreenEditGroup;
            addANewGroupViewController.useTableIndex = YES;
            addANewGroupViewController.allowSearchControl = YES;
            addANewGroupViewController.groupTitleSelectedForRename = groupTitleSelectedForRename;
            [self.navigationController pushViewController:addANewGroupViewController animated:YES];

 //[self getGroupNameAlert:groupTitleSelectedForRename ifAlreadyExists:NO];
        }
        break;
    }
    case 1:
    {

        NSIndexPath* indexPath = [self.groupListTableView indexPathForCell:cell];
        // Change the cell appearance
        NSArray* arrayOfKeys = (NSArray *)self.groupsInfoDict.allKeys;
        NSArray *sortedValues = [arrayOfKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
        selectedGroupKey = [sortedValues objectAtIndex:indexPath.row];

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure you want to delete this group?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
        [alert setTag:990];
        [alert show];


        break;
    }
    default:
        break;
  }
}

  - (BOOL)swipeableTableViewCellShouldHideUtilityButtonsOnSwipe:(SWTableViewCell *)cell
  {
  // allow just one cell's utility button to be open at once
   return YES;
  }

 - (BOOL)swipeableTableViewCell:(SWTableViewCell *)cell canSwipeToState:(SWCellState)state{

  switch (state) {
    case 1:
        // set to NO to disable all left utility buttons appearing
        return YES;
        break;
    case 2:
        // set to NO to disable all right utility buttons appearing
        return YES;
        break;
    default:
        break;
    }

  return YES;
   }

0 个答案:

没有答案