1

NSString 変数に問題があります。

.h ファイル

    NSString *strDeleteFilePath;
    @property (nonatomic,retain) NSString* strDeleteFilePath;

.m ファイル

    @synthesize strDeleteFilePath;

//その後、削除ボタンクリック時

    -(IBAction)deleteButton:(id)sender {
        UIButton *bt=(UIButton *)sender;
        strDeleteFilePath=[FunctionManager getDocumentDirectoryPath:@"MyPhotos"];
        strDeleteFilePath=[NSString stringWithFormat:@"%@/%@",strDeleteFilePath,[arrSaveImage objectAtIndex:bt.tag]];
        NSLog(@"strDeletePath=%@",strDeleteFilePath);

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure you want to delete this photo" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
        [alert show];
        [alert release];
    }

nslog は、次のように適切なパスを文字列で出力します。

strDeletePath=/Users/Samir/Library/Application Support/iPhone Simulator/6.0/Applications/A72B7488-ABCB-48EC-91D0-CEE87FA121FE/Documents/MyPhotos/Dt20130411164806.png

アラートビューで削除ボタンをクリックすると...

   - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
       if (buttonIndex == 0){
           NSFileManager *fileManager = [NSFileManager defaultManager];
           NSError *error = nil;
           if(![fileManager removeItemAtPath:strDeleteFilePath error:&error]) {
               NSLog(@"Delete failed:%@", error);
           } else {
               NSLog(@"image removed: %@", strDeleteFilePath);
           }
           [self setScrollviewItem];
       }
   }

if(![fileManager removeItemAtPath:strDeleteFilePath error:&error]) 行でクラッシュし、次のエラー ExE_BAD..ACCESS... が発生します。

エラー ExE_Bad.....

前もって感謝します。

4

3 に答える 3

0

これを試して

-(IBAction)deleteButton:(id)sender {
    UIButton *bt=(UIButton *)sender;
    strDeleteFilePath=[FunctionManager getDocumentDirectoryPath:@"MyPhotos"];
    strDeleteFilePath=[[NSString alloc] initWithFormat:@"%@/%@",strDeleteFilePath,[arrSaveImage objectAtIndex:bt.tag]]; //change is here
    NSLog(@"strDeletePath=%@",strDeleteFilePath);

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure you want to delete this photo" delegate:self cancelButtonTitle:@"Delete" otherButtonTitles:@"Cancel", nil];
    [alert show];
    [alert release];
}
于 2013-04-12T05:32:32.620 に答える
0

これを置き換えます:

 if(![fileManager removeItemAtPath:strDeleteFilePath error:&error]) {
           NSLog(@"Delete failed:%@", error);
       } else {
           NSLog(@"image removed: %@", strDeleteFilePath);
       }

と:

if([fileManager fileExistsAtPath: strDeleteFilePath])
{
   [fileManager removeItemAtPath: strDeleteFilePath error: nil];
}
else{
   NSLog(@"File not found");
}
于 2013-04-12T06:06:15.643 に答える