我有两个图像视图。当我单击第一个图像视图下方的按钮(例如takePhoto)时,拍摄的照片将出现在第一个图像视图中。然而,当我点击第二个"拍摄两张"按钮,我希望第二张照片出现在第二张图片视图中(imageTwo)。现在,如果我使用第二张照片拍摄照片,拍摄照片和拍摄照片。按钮,最终(相同)图像出现在两个图像视图中。请参阅下面的代码 - 有谁知道如何解决这个问题?我希望我能够很好地解释这一点。
E.g。
使用takePhoto(按钮)拍摄的照片应该出现在imageView中,而拍摄照片拍摄的照片(按钮)应该出现在imageTwo中。
ViewController.m
- (IBAction)selectPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)takePhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)selectPhotoTwo:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *secondImage = info[UIImagePickerControllerEditedImage];
self.imageTwo.image = secondImage;
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:2)
这可以通过跟踪点击哪个按钮或根据点击的按钮存储对正确图像视图的引用来轻松实现。然后在图像选择器委托方法中设置适当的图像视图。
添加名为UIImageView *
的<{1}}类型的实例变量。
然后按如下方式更新其余代码:
selectedImageView
答案 1 :(得分:2)
问题是无论点击哪个按钮,你都会给你的UIImagePickerController提供相同的import datetime as dt
from pandas.tseries.holiday import AbstractHolidayCalendar, Holiday, nearest_workday, \
USMartinLutherKingJr, USPresidentsDay, GoodFriday, USMemorialDay, \
USLaborDay, USThanksgivingDay
class USTradingCalendar(AbstractHolidayCalendar):
rules = [
Holiday('NewYearsDay', month=1, day=1, observance=nearest_workday),
USMartinLutherKingJr,
USPresidentsDay,
GoodFriday,
USMemorialDay,
Holiday('USIndependenceDay', month=7, day=4, observance=nearest_workday),
USLaborDay,
USThanksgivingDay,
Holiday('Christmas', month=12, day=25, observance=nearest_workday)
]
def get_trading_close_holidays(year):
inst = USTradingCalendar()
return inst.holidays(dt.datetime(year-1, 12, 31), dt.datetime(year, 12, 31))
if __name__ == '__main__':
print(get_trading_close_holidays(2016))
# DatetimeIndex(['2016-01-01', '2016-01-18', '2016-02-15', '2016-03-25',
# '2016-05-30', '2016-07-04', '2016-09-05', '2016-11-24',
# '2016-12-26'],
# dtype='datetime64[ns]', freq=None)
。因此调用相同的delegate
。但是在那时你无法知道哪个按钮被点击了,所以你无法知道将图片放入哪个图像视图。
为每个不同的按钮赋予UIImagePickerController不同的imagePickerController:didFinishPickingMediaWithInfo:
,或者在某个实例变量中存储一些关于触发了哪个按钮的信息,以便delegate
可以正确地决定要做什么。