我肯定在这里遗漏了一些东西。这应该没那么难。我正在尝试在 iPad 上的 UITableView 中的项目列表上实现基本的滑动删除功能。一切似乎都正常,除了当单元格向左滑动时没有删除按钮,只有空白区域。以下是我在适当功能中的内容。
- (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
}
}
EDIT:
只是尝试随机的事情,我添加了以下代码。当我滑动列表单元格时,我看到我创建的红色删除按钮出现一瞬间,然后滑出单元格的右边缘。因此,从外观上看,iOS 将 editAccessory 视图置于单元格边缘之外。仍在尝试找出原因。
- (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 的主视图下。以下代码行解决了该问题。
[self.mainMenu.view setFrame:CGRectMake(0, 0, MENUWIDTH, self.view.frame.size.height)];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)