我正在使用图片选择器拍摄照片并将其保存到数据库中。一旦我将其保存在数据库中,我就会发出一个警报视图,说明图像已保存,当我点击确定时,我需要关闭图像选择器视图,我需要显示另一个视图。
这是我的
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self takePic];
}
-(void)takePic{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate =self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==1) {
if (buttonIndex==0) {
UIImagePickerController *picker;
[picker dismissViewControllerAnimated:YES completion:NULL]; // here i am not able to dismiss the image picker view
Tab *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"Tabbar"];
[self presentViewController:vc animated:YES completion:nil];
}
}
}
我可以忽略选择器视图,如果我没有放置视图中的[self takepic]确实出现。
我也试过
[picker dismissViewControllerAnimated:YES completion:^{
[self presentViewController:vc animated:YES completion:NULL];
}];
但我无法忽略选择器视图。我收到警告:"警告:尝试显示其视图不在窗口层次结构中!"
任何人都可以告诉我,如何解雇选择器视图
答案 0 :(得分:0)
试试这个。我想这会对你有所帮助
在您的代码中,您正在通过UIImagePickerController *picker;
对UIImagePicker进行新的引用
你应该解雇相同的图像选择器
-(void)takePicture{
picker = [[UIImagePickerController alloc] init];
picker.delegate =self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag==1) {
if (buttonIndex==0) {
[picker dismissViewControllerAnimated:YES completion:NULL]; // here i am not able to dismiss the image picker view
}
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Hello" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
alert.tag = 1;
[alert show];
}
答案 1 :(得分:0)
您需要制作一个属性来打开和关闭相机
@property (assign) BOOL *makeCameraOff;
-(void)viewDidAppear:(BOOL)animated{
if (makeCameraOff==NO) {
[self performSelector:@selector(takePic) withObject:nil afterDelay:0.3];
}
}
-(void)takePic{
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 {
//here change the BOOL value to YES,so that you can dismiss the camera view
makeCameraOff=YES;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
// your code to present the view controller you need;
}