2
我肯定是在这里失踪的东西。这应该不那么难。我试图在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
}
}
编辑:
只是想随意的事情,我添加以下代码。当我滑动列表单元格时,看到我创建的红色删除按钮出现一瞬间,然后从单元格的右边缘滑落。所以,从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];
}
确保在前两个方法中通过设置断点来触发那些IF语句中的代码。 – hgwhittle
是否做到了。我是。 – iHorse
根据'[indexPath row]> 1'代码判断,我相信这意味着您的第一个和第二个单元格将不会被设置为编辑样式。你是故意的吗? – hgwhittle