我对 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...
先感谢您。