【问题标题】:capture image is not working properly.?捕获图像无法正常工作。?
【发布时间】:2015-07-25 22:52:49
【问题描述】:

您好,我是开发 iOS 应用程序的新手,请帮助我。我在使用UIImagePicker 捕获图像时遇到问题。我已将 hip mob 应用程序集成到我们的应用程序中。

在该窗口中,我想显示一个UIButton,以便用户单击该UIButton 应该捕获图像。当我单击按钮时,它会抛出一条消息(其视图不在窗口层次结构中!)。

我认为这是由于这个聊天窗口造成的。这是我的代码 sn-p。!

[[HMService sharedService] openChat:self withSetup:^(HMChatViewController * controller)
{
 controller.chatDelegate = self;
 controller.chatView.receivedMessageFont = [UIFont systemFontOfSize:20.0];
 controller.navigationBarHidden = YES;
 UIView * viewObjForVehicleDetails = [[UIView alloc]init];
 UIButton * btnForCaputrePhoto = [[UIButton alloc]init];
 [btnForCaputrePhoto addTarget:self action:@selector(CapturePhotoImage) forControlEvents:UIControlEventTouchUpInside];
  btnForCaputrePhoto.frame = CGRectMake(55, 90, 103, 85);
 [controller.chatView addSubview:viewObjForVehicleDetails];
 [viewObjForVehicleDetails addSubview:btnForCaputrePhoto];
 [[controller.chatView table] registerClass:[ChatTableViewCell class] forCellReuseIdentifier:@"ReuseChatTableViewCell"]; 
} 


 -(void)CapturePhotoImage
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:NO completion:nil];

}   


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}

提前致谢!

【问题讨论】:

  • 图像选择器是否正在显示?或者它正在崩溃
  • 感谢您的回复..!不,它没有显示图像选择器,我在设备中进行了测试,所以它不会崩溃。我想我正在使用 hipmob 控制器,我正在添加按钮,所以它不能导航 imagePickerView
  • 你添加了 viewObjForVehicleDetails 的 self.view 添加子视图
  • 我想在该控制器上显示此图像而不是在视图中,因此我将此 viewObjForVehicleDetails 添加到控制器而不是查看。这就是为什么会出现这个问题..@Anbu.Karthik
  • 如何将图像选择器添加到其他控制器而不是 self.view..?@Anbu.Karthik, @Vizllx

标签: ios uitableview uiviewcontroller uiimagepickercontroller


【解决方案1】:

首先确保您在视图控制器中使用以下委托

<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

第二次使用这一行来显示 ImagePicker:-

[self presentModalViewController:picker animated:YES];

替代方式:-

[self.view addSubview:imagePicker.cameraOverlayView]

【讨论】:

  • 是的,我已经给出了这些委托方法,并且我还给出了 [self presentModalViewController:picker animated:YES];即使没有变化,我的代码也是如此。它显示相同的消息[其视图不在窗口层次结构中!]
  • 请帮助我@Vizllx
  • @AppDeveloper- 检查替代答案。
  • 我已经检查了这种替代方式。我力所能及地收到任何消息。而且我也得到了 imagePicker,我认为 3 rd 方控制器与此视图重叠,因此此图像选择器可能会显示在此控制器下
  • 你能检查一下 waht 是 imagePicker 框架,还是只检查 NSLog(@"%@",imagePicker);并在此处记录详细信息。
【解决方案2】:

改变方法声明如下

- (IBAction) CapturePhotoImage:(id)sender
{
    NSLog("Called");
}

并且方法调用“CapturePhotoImage”为CapturePhotoImage:

 [btnForCaputrePhoto addTarget:self action:@selector(CapturePhotoImage:) forControlEvents:UIControlEventTouchUpInside];

【讨论】:

  • 不,它没有显示图像选择器,并抛出一条消息,因为它的视图不在窗口层次结构中!
猜你喜欢
  • 2012-02-10
  • 1970-01-01
  • 2015-01-22
  • 2020-09-11
  • 1970-01-01
  • 2013-04-17
  • 2019-01-11
  • 2012-07-04
  • 1970-01-01
相关资源
最近更新 更多