滑动以删除不显示删除按钮 [英] swipe to delete not showing the delete button

查看:115
本文介绍了滑动以删除不显示删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我肯定在这里遗漏了一些东西。这不应该那么难。我正在尝试在iPad上的UITableView中的项目列表上实现基本滑动以删除功能。一切似乎都有效,除非单元格向左滑动时没有删除按钮只是空白空格。下面是我在相应函数中的内容。

I'm definitely missing something here. This should not be that hard. I am trying to implement the basic swipe to delete function on a list of items in a UITableView on an iPad. Everything seems to work except when the cell slides to the left there is NO delete button just empty white space. Below is what I have in the appropriate functions.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.state == AMListMenu && [indexPath row] > 1)
    {
        return YES;
    }

    return NO;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.state == AMListMenu && [indexPath row] > 1)
    {
        return UITableViewCellEditingStyleDelete;
    }

    return UITableViewCellEditingStyleNone;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }
}

编辑:

只是尝试随机的东西我添加了以下代码。当我滑动列表单元格时,我看到我创建的红色删除按钮瞬间出现,然后滑出单元格的右边缘。因此,从iOS的外观来看,editAccessory视图不在单元格的边缘。仍在试图找出原因。

Just trying random things I added the following code. When I swipe the list cell I see the red delete button I created appear for a split second and then slide off the right edge of the cell. So, from the looks of things iOS is putting the editAccessory view off the edge of the cell. Still trying to figure out why.

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    MainMenuCell *cell = (MainMenuCell *)[tableView cellForRowAtIndexPath:indexPath];

    UIButton* btn = [[UIButton alloc]init];
    [btn setTitle:@"DELETE" forState:UIControlStateNormal];
    [btn setTitleColor:AMColorWhite forState:UIControlStateNormal];
    [btn setBackgroundColor:AMColorTradeMarkRed];
    [btn setFrame:CGRectMake(242, 0, 90, cell.frame.size.height)   ];

    [cell setEditingAccessoryView:btn];
    [cell.contentView addSubview:btn];
}


推荐答案

我应该发布这个不久前我忘了显然iOS正在调整菜单ViewController下的幻灯片调整到全屏,没有任何理由,无需调整列表项的子视图。所以当我刷卡删除时,删除按钮隐藏在父ViewController的主视图下。以下代码行修复了问题。

I should of posted this a while ago but I forgot. Apparently iOS was resizing the slide under menu ViewController to full screen for no good reason without resizing the subviews of the list items. So when I swiped to delete the delete button was hidden under the main view of the parent ViewController. The following line of code fixed the problem.

[self.mainMenu.view setFrame:CGRectMake(0, 0, MENUWIDTH, self.view.frame.size.height)];

这篇关于滑动以删除不显示删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆