iOS - How to call imagepicker delegate method two times when picking images from different button with actionsheet in iphone
how to call imagepicker delegate method two times when picking images from different button with actionsheet in iphone
Code (Objective-C)
-(IBAction)before:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = 1;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
-(IBAction)after:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = 2;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (actionSheet.tag)
{
case 1:
switch (buttonIndex)
{
case 0:
{
#if TARGET_IPHONE_SIMULATOR
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Saw Them" message:@"Camera not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
#elif TARGET_OS_IPHONE
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:nil];
[picker release];
#endif
}
break;
case 1:
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
[picker release];
}
break;
}
break;
case 2:
switch (buttonIndex)
{
case 0:
{
#if TARGET_IPHONE_SIMULATOR
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Saw Them" message:@"Camera not available." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
#elif TARGET_OS_IPHONE
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:nil];
[picker release];
#endif
}
break;
case 1:
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentViewController:picker animated:YES completion:nil];
[picker release];
}
break;
}
break;
default:
break;
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
image1 = [info objectForKey:UIImagePickerControllerOriginalImage];
if (image1 != nil)
{
NSError *error;
NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:@"progress"];
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];
if (beforebtn.tag == 4) {
NSString *anImageName = [NSString stringWithFormat:@"before.png"];
NSString *anImagePath = [NSString stringWithFormat:@"%@/%@", dataPath, anImageName];
NSData *anImageData = UIImagePNGRepresentation(image1);
beforeimg.image = [[UIImage alloc] initWithData:anImageData];
}else if(beforebtn.tag == 5){
NSString *anImageName = [NSString stringWithFormat:@"after.png"];
NSString *anImagePath = [NSString stringWithFormat:@"%@/%@", dataPath, anImageName];
NSData *anImageData = UIImagePNGRepresentation(image1);
afterimg.image = [[UIImage alloc] initWithData:anImageData];
}
}
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self dismissViewControllerAnimated:YES completion:NULL];
}else{
[self.popoverController dismissPopoverAnimated:YES];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
{
[self.navigationController dismissViewControllerAnimated: YES completion: nil];
}
Every time image save before image only. How to after imageTag : Mobile, iOS, iPhone, Objective-C, Mobile
ประวัติการแก้ไข 2013-12-13 20:29:54
Date :
2013-12-10 12:41:02
By :
vishwa
View :
1210
Reply :
1
Date :
2013-12-13 09:54:43
By :
mr.win
Load balance : Server 04