4

所以,这个问题是上一期的后续问题,但我决定发布一个新问题以保持相关性和整洁性。

UITableViewRowAnimationFade基本上,当调用以下代码时,和之间没有区别UITableViewRowAnimationNone

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{

    [tvController.tableView beginUpdates];

    if (editing == YES) {
        [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade];

    }else {

        UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone;
        [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation];

        [tvController.tableView reloadSectionIndexTitles];

        self.navigationItem.hidesBackButton = editing;
    }
    [tvController.tableView endUpdates];
}

非常感谢任何帮助。它仍然进入编辑模式,但没有动画,尽管 YES 被传递给动画。


编辑:当我使用以下代码实际删除内容时,动画效果很好:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

        NSString *stuff = [documentsPath stringByAppendingPathComponent:@"stuff.plist"];
        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:stuff];

        if (fileExists) {

            NSMutableDictionary *propertyList = [[NSMutableDictionary alloc] initWithContentsOfFile:enteredPlaces];
            [propertyList removeObjectForKey:[[settingsArray objectAtIndex:1] objectAtIndex:indexPath.row]];
            [propertyList writeToFile:stuff atomically:YES];
        }

        [[settingsArray objectAtIndex:1] removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];

    } 
}

当用户按下编辑按钮并且表格进入编辑模式时它不起作用,表格视图只是静态地进入编辑模式。

4

3 回答 3

0

我的应用程序中有相同的场景,我遇到了类似的问题。我想下面的函数会解决你的问题:

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{

    [tvController.tableView setEditing:editing animated:animated]; //this LOC is added 

    [tvController.tableView beginUpdates];

    if (editing == YES) {
        [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade];

}    else {

        UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone;
        [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation];

        [tvController.tableView reloadSectionIndexTitles];

        self.navigationItem.hidesBackButton = editing;
    }
        [tvController.tableView endUpdates];
}


-(void)deleteRecord:(NSInteger)recordNo:(NSInteger)sectionNo:(BOOL)isEditMode:(BOOL)isAnimate {

if(isEditMode){
    NSIndexPath *indexP=[NSIndexPath indexPathForRow:recordNo inSection:sectionNo];
    [tvController.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationLeft];
}
else {

    if(isAnimate)
        [tvController.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationFade];
    else
        [tvController.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexP, nil] withRowAnimation:UITableViewRowAnimationNone];

    [tvController.tableView reloadSectionIndexTitles];
    self.navigationItem.hidesBackButton = editing;

}


[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(reload) userInfo:nil repeats:NO];
}


 -(void)reload {
    [table reloadData];
}
于 2012-07-07T05:30:36.147 回答
0

如果您唯一恼火的是删除不会消失的事实,那是因为您正在期待界面不提供的东西。

您提到您知道可以将单个单元格设置为不可编辑,这是执行此操作的标准方法。该机制根本不会预期不使用 UITableViewDataSource 来提供有关显示内容的信息(或者,在您的情况下,只是通过点击编辑/完成按钮来提供正在更改的数据中的内容)。

通过尝试将两者结合起来,您会混淆应该发生的动画。

可能你能做的最好的事情如下(动画持续时间和长度可能为0,因为你在tableView中要求单独的动画),这将导致你的动画在打开编辑的动画之后发生模式。

- (void) setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];  // possibly not necessary depending upon your class hierarchy
    [tvController.tableView setEditing:editing animated:animated];
    [UIView animateWithDuration:0.25 delay:0.05 options:UIViewAnimationCurveLinear
                     animations:^{ 
                         [tvController.tableView beginUpdates];

                         if (editing == YES) {
                             [tvController.tableView deleteRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:UITableViewRowAnimationFade];
                         } else {
                             UITableViewRowAnimation animation = animated ? UITableViewRowAnimationFade : UITableViewRowAnimationNone;
                             [tvController.tableView reloadRowsAtIndexPaths:[settingsArray objectAtIndex:0] withRowAnimation:animation];
                             [tvController.tableView reloadSectionIndexTitles];
                             self.navigationItem.hidesBackButton = editing;
                         }
                         [tvController.tableView endUpdates];
                     }
                     completion:nil];
}
于 2012-07-08T04:07:13.180 回答
0
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [db DeleteData:[NSString stringWithFormat:@"%d",indexPath.row]];
        [data removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation: UITableViewRowAnimationFade];

    }   

}
于 2012-07-07T07:21:22.523 回答