2011-01-08 21 views
0
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
UIImage *tempImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 
imgview.image = tempImage; 
[self dismissModalViewControllerAnimated:YES]; 
[picker release]; 
} 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
[self dismissModalViewControllerAnimated:YES]; 
[picker release]; 
} 


-(IBAction) calllib 
{ 
img1 = [[UIImagePickerController alloc] init]; 
img1.delegate = self; 
img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
[self presentModalViewController:img1 animated:YES]; 

} 

all the codes above works well for taking out photos from the photo library. 
problem is that when i tried to use it under the UIActionSheet it does not work. 
i just copy the lines of codes from the -(IBAction) calllib as follow. 


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
UIImage *detectface = [Utilities detectFace:imgview.image]; 
UIImage *grayscale = [Utilities grayscaleImage:imgview.image]; 
UIImage *avatars = [Utilities avatars:imgview.image]; 

img1 = [[UIImagePickerController alloc] init]; 
img1.delegate = self; 
img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

switch (buttonIndex) 
{ 
    case 0: 
    [self presentModalViewController:img1 animated:YES]; 
    imgview.image = detectface; 
    break; 
    case 1: 
    [self presentModalViewController:img1 animated:YES]; 
    imgview.image = grayscale; 
    break; 
    case 2: 
    [self presentModalViewController:img1 animated:YES]; 
    imgview.image = avatars; 
    break; 

    default: 
    break; 
} 

} 

它不起作用。有人能幫我弄清楚是什麼問題?如何使UIImagePickerController在開關盒下工作UIActionSheet

沒有[self presentModalViewController:img1 animated:YES]; switch case可以正常工作; ...

感謝

+0

緊急..請幫助我..謝謝在後前進.. – Phy 2011-01-08 12:54:25

+0

開關櫃的作品!但只有當我在UIImage上有圖像。現在的問題是,在我選擇了一個案例之後,代碼看起來像是在同一時間一起運行。它會改變圖像,然後只會去照片庫。 – Phy 2011-01-08 13:07:11

回答

0
img1 = [[UIImagePickerController alloc] init]; 
img1.delegate = self; 
img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

switch() { 
    case 0: 
    [self presentModalViewController:img1 animation:YES]; 
} 

– (void)imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)dict { 
    UIImage *image = [dict objectForKey:SOME_KEY_HERE]; 
    imageView.image = [Utilities detectFace:image]; 

} 

你需要調用臉檢測你得到的圖像,這意味着在委託方法從返回的UIImagePickerController