iphone - UITableViewRowAnimationFade 不工作

标签 iphone objective-c ios uitableview

所以,这个问题是从 a previous issue 开始的, 但我决定发布一个新问题以保持相关性和整洁性。

基本上,当调用下面这段代码时,UITableViewRowAnimationFadeUITableViewRowAnimationNone 没有区别:

- (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];

    } 
}

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

最佳答案

- (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];

    }   

}

关于iphone - UITableViewRowAnimationFade 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11334221/

相关文章:

ios - 如何将钥匙串(keychain)共享功能添加到我的 App ID?

iphone - 转换为灰度 - 太慢

iphone - iOS - 强制 UIWebView 加载内容?

ios - 为什么 UITableView 的 NSMutableArray 数据在被 tableView 使用时丢失 :cellForRowAtIndexPath?

ios - 在 iOS 上播放多种声音会产生变形金刚般的噪音

iphone - 在 Objective-c 中实现协议(protocol)方法

ios - View Controller 中的两个 TextField 设置为委托(delegate),导致应用程序因 NSRange、范围或索引超出范围而崩溃

ios - 是否可以将 View 从场景停靠栏中拖到它自己的 XIB 中?

ios - 如何在 Xcode 7 中嵌入 Cocoa Touch Framework

objective-c - IOS - CoreData - 插入具有已插入关系实体的新实体