2011-12-02 2 views
0

컨텍스트
내 응용 프로그램에는 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 삭제할 수 있도록 전)
.

내 방법에서 무엇이 잘못 되었나요? 내 앱 또는 내 문제와 관련하여 명확성이 부족한 경우 요청하지 말고 부끄럽게 생각하지 마십시오.

미리

은 사용자가 작업 시트의 옵션 버튼 중 하나를 클릭 한 후 작업을 처리하기 위해 시도하는 것처럼 소리
+0

당신이 imageView.image = nil을 호출하고 있기 때문에 그렇지 않습니다. 첫 줄에? – Novarg

+0

네, 맞습니다. 그러나 "삭제"버튼을 클릭 한 후 이미지를 삭제할 수 있습니까? – Studie

답변

0

에 도움을 주셔서 감사합니다. 그러나 액션 시트가 표시되기 전에 willPresentActionSheet 함수가 호출됩니다. 사용자가 작업 시트에서 확인을 클릭 한 후에 만 ​​이미지를 삭제하려고하는 경우 UIActionSheetDelegate에서 clickedButtonAtIndex 함수를 살펴보십시오.

(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 

것은 다시 작업 시트 호출 기능 (- 위 보여으로 "자기"가장 가능성)을 처리하는 클래스에 UIActionSheet의 대리자를 지정해야합니다.

clickedButtonAtIndex 처리기에서이 태그를 사용하여 UIActionSheets을 차별화하고 단추 인덱스를 사용하여 클릭 한 항목을 확인할 수 있습니다.