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

  • Dan Gately

    Dan Gately

    13 AĞUSTOS 2006
  • hockeywebcasts

    hockeywebcas

    31 EKİM 2012
  • TheGamer2323

    TheGamer2323

    25 Ocak 2009