我正在嘗試使用tableview /數組組合來從文檔目錄中刪除文件。 出於某種原因,指向Documents目錄路徑的我的NSString
正在轉換爲NSCFType
(經過一些調查,我明白因爲變量未被釋放而發生)。正因爲如此,該應用程序崩潰在行NSCFType一直在發生,有些東西沒有被釋放?
NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:temp];
聲稱NSCFType
無法識別方法stringByAppendingPathComponent
。
如果有人能幫助我,我將不勝感激(希望我已經足夠清楚地解釋了這一點)。
- (void) tableView: (UITableView *) tableView
commitEditingStyle: (UITableViewCellEditingStyle) editingStyle
forRowAtIndexPath: (NSIndexPath *) indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSString *temp = [directoryContent objectAtIndex:indexPath.row];
NSLog(temp);
NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:temp];
[[NSFileManager defaultManager] removeItemAtPath:lastPath error:nil];
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
directoryContent = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil] retain];
//tableview handling below
}
後,您可以設置documentsDirectory –
比較遺憾的是代碼,編輯。 – user1493543
Documentsdirectory肯定是在某處發佈的。它是強大的還是保留的(ARC或MRC)。 – CodaFi