SORU
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ş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • MagicofRahat

    MagicofRahat

    13 Temmuz 2007
  • psidot

    psidot

    2 Kasım 2006
  • Rachel Raum

    Rachel Raum

    10 EYLÜL 2007