22 ŞUBAT 2013, Cuma
Sil belge dizinde belirtilen dosya
App belge dizini bir resmi silmek istiyorum. Görüntüyü silmek için yazdığım bir kod
-(void)removeImage:(NSString *)fileName
{
fileManager = [NSFileManager defaultManager];
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsPath = [paths objectAtIndex:0];
filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", fileName]];
[fileManager removeItemAtPath:filePath error:NULL];
UIAlertView *removeSuccessFulAlert=[[UIAlertView alloc]initWithTitle:@"Congratulation:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[removeSuccessFulAlert show];
}
Çalışma kısmen. Bu kod dizininden bir dosya, ama dizinin içeriğini kontrol ettiğimde, hala resim isimlerini gösteren siliniyor. Tamamen dizinden bu dosyayı kaldırmak istiyorum. Ben kod aynı yapmak için ne gibi bir değişiklik yapmalıyım? Teşekkürler
CEVAP
22 ŞUBAT 2013, Cuma
Benim için onun çalışma.. kodunuzu kontrol ettim. Aşağıda değiştirilmiş kodunu kullanarak alıyorsanız, herhangi bir hata için kontrol edin
- (void)removeImage:(NSString *)fileName
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:fileName];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if (success) {
UIAlertView *removeSuccessFulAlert=[[UIAlertView alloc]initWithTitle:@"Congratulation:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[removeSuccessFulAlert show];
}
else
{
NSLog(@"Could not delete file -:%@ ",[error localizedDescription]);
}
}
Bunu Paylaş:
Nasıl bir dosya veya dizin yolu ile be...
Nasıl bir dosya oluşturmak için java b...
VS2005: Meclis '<Meclis>�...
Nasıl her dosya için bir şey yapmak iç...
Nasıl CURL ile veri belirtilen POST is...