컨텍스트
내 응용 프로그램에는 UIBarButtonItems
두 개가 있습니다. save-button이라는 첫 번째 버튼을 클릭하면 UIActionSheet
이 나타나서 저장하도록 요청합니다. 저장 프로세스를 수락하면 실제 이미지가 라이브러리에 저장됩니다.UIActionSheet : 올바른 연대기에 메서드 호출을 처리하십시오.
삭제 버튼이라는 두 번째 버튼을 클릭하면 UIActionSheet
을 통해 동일한 요청이 시작됩니다. 작업을 수락 한 후 이미지를 삭제해야합니다.
두 가지 방법이 IBAction
이고 하나는 UIActionSheet
입니다. 방법 "willPresentActionSheet는"수업 시간에 두 번을 구현할 수 없다는 이유
-(IBAction)save: (id) sender{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle: @"Sure to save?"delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: @"Save",@"Cancel",nil];
actionSheet.tag = 100;
[actionSheet showInView:self.view];
[actionSheet release];
}
-(IBAction)bin: (id) sender{
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"Sure to delete?"delegate: self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Delete",@"Cancel",nil];
actionSheet.tag = 101;
[actionSheet showInView:self.view];
[actionSheet release];
}
의
구현, 내가 저장 - 및 삭제 버튼을 처리하기 위해 태그를 사용합니다.
-(void)willPresentActionSheet:(UIActionSheet*)actionSheet{
if (actionSheet.tag == 100) {
CGRect contextRect = CGRectMake(0, 960, 768, 1004);
UIGraphicsBeginImageContext(contextRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);
} else if (actionSheet.tag == 101) {
imageView.image = nil;
NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Default.png"];
[imageView setImage:[UIImage imageWithContentsOfFile:filePath]];
}
}
문제점
나는 actionSheet가 나타납니다 삭제 - 버튼을 누르면,하지만 같은 시간에 이미지가 아직 삭제 (I 삭제할 수 있도록 전).
내 방법에서 무엇이 잘못 되었나요? 내 앱 또는 내 문제와 관련하여 명확성이 부족한 경우 요청하지 말고 부끄럽게 생각하지 마십시오.
미리은 사용자가 작업 시트의 옵션 버튼 중 하나를 클릭 한 후 작업을 처리하기 위해 시도하는 것처럼 소리
당신이 imageView.image = nil을 호출하고 있기 때문에 그렇지 않습니다. 첫 줄에? – Novarg
네, 맞습니다. 그러나 "삭제"버튼을 클릭 한 후 이미지를 삭제할 수 있습니까? – Studie