[英]UITableView is not reloading after I delete all files from Document Directory
請在這里快速幫助:-)
我已經用文檔目錄的內容填充了UITableView,並且可以通過一個按鈕從目錄中刪除所有文件。
現在,當我刪除文件時,用戶看到的列表仍然是相同的,並且直到我重新加載視圖后,它才會顯示這些文件確實消失了。
我已經按照下面的代碼使用了:
[_mainTableView reloadData];
[_mainTableView beginUpdates]; & [_mainTableView endUpdates];
這些都不起作用,但是一旦這些文件消失了,我就需要tableView刷新。
[_mainTableView beginUpdates];
NSFileManager *fileMgr = [[NSFileManager alloc] init];
NSError *error = nil;
NSArray *directoryContents = [fileMgr contentsOfDirectoryAtPath:[self filePath] error:&error];
NSLog(@"FILES - %@", directoryContents);
if (error == nil) {
for (NSString *path in _mainDataArray) {
NSString *fullPath = [[self filePath] stringByAppendingPathComponent:path];
BOOL removeSuccess = [fileMgr removeItemAtPath:fullPath error:&error];
if (!removeSuccess) {
// Error handling
}
else if(removeSuccess)
{
[_mainTableView reloadData];
}
}
}
[_mainTableView endUpdates];
我還需要嘗試其他嗎?
我認為您不需要創建NSFileManager
的新實例; 改為使用:
[NSFileManager defaultManager];
第一個if條件if (error == nil)
將為true,因為錯誤為nil,所以我不認為它會在for循環內進行
您不會清空用於填充表格的數組。 您正在使用數組中的數據刪除文件夾中的項目,但未從數組中刪除項目,因此,當然,表仍在填充中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.