ios - 2 UIButtons to set 2 UIImageViews -
i've 2 uibutton
s, want both buttons pick image, button1
setting image imageview1
, button2
imageview2
. created button1
picks image , set imageview1
image, if i'm creating button2
, don't have in:
- (ibaction)chooseimage1:(id)sender { imagepicker.delegate = self; imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary; [self presentviewcontroller:imagepicker animated:yes completion:nil]; } - (ibaction)chooseimage2:(id)sender { imagepicker.delegate = self; imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary; [self presentviewcontroller:imagepicker animated:yes completion:nil]; } uiimage *image; -(void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { nsurl *mediaurl; mediaurl = (nsurl *)[info valueforkey:uiimagepickercontrollermediaurl]; image = (uiimage *)[info valueforkey:uiimagepickercontrolleroriginalimage]; imageview1.image=image; [picker dismissviewcontrolleranimated:yes completion:nil]; } -(void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { [picker dismissviewcontrolleranimated:yes completion:nil]; }
create index in .h
file.
nsuinteger *selectedimageindex;
and in .m
file :
- (void)showimagepicker:(uiimagepickercontrollersourcetype)source{ uiimagepickercontroller *ipc = [[uiimagepickercontroller alloc] init]; ipc.sourcetype = source; ipc.allowsediting = yes; ipc.delegate = self; [self presentmodalviewcontroller:ipc animated:yes]; } - (ibaction)chooseimage1:(id)sender { selectedimageindex = 1; [self showimagepicker:uiimagepickercontrollersourcetypephotolibrary]; } - (ibaction)chooseimage2:(id)sender { selectedimageindex = 2; [self showimagepicker:uiimagepickercontrollersourcetypephotolibrary]; } -(void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { uiimage *img = [info objectforkey:@"uiimagepickercontrollereditedimage"]; if (!img) img = [info objectforkey:@"uiimagepickercontrolleroriginalimage"]; if (selectedimageindex == 1) imageview1.image=img; else imageview2.image = img; [picker dismissviewcontrolleranimated:yes completion:nil]; } -(void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { [picker dismissviewcontrolleranimated:yes completion:nil]; }
but again, 1 way it.
Comments
Post a Comment