簡體   English   中英

iPhone / Obj-C-存檔對象導致滯后

[英]iPhone/Obj-C - Archiving object causes lag

嗨,我有一個表格視圖,當我刪除一個單元格時,我要從NSMutableArray中刪除一個項目,將其歸檔,然后刪除該單元格。

但是,當我這樣做時,這導致刪除按鈕在單擊后滯后。 有沒有什么辦法解決這一問題?

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        int row = [indexPath row]; 
        [savedGames removeObjectAtIndex:row]; 
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

        //this line causing lag
        [NSKeyedArchiver archiveRootObject:savedGames toFile:[self dataFilePath]];
    }    

}

謝謝

聽起來您已經知道答案了-不要在每次刪除時都存檔所有內容。 這可以通過多種方式完成-一次僅歸檔片段,延遲歸檔(定期/退出時/其他策略),或者使自定義歸檔代碼的速度大大提高,我懷疑這在以下情況下是否會起到很大作用:東西。 聽說 MAKeyedArchiver的速度比NSKeyedArchiver快,但我相信這是前一段時間,並且是針對Mac +潛在平台而設計的(從好的方面來說,它是當時NSKeyedArchiver API的替代品,因此如果您選擇使用它,集成時間應該很少。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM