捕获图像无法正常工作。

时间:2015-05-14 10:46:45

标签: ios uitableview uiviewcontroller uiimagepickercontroller

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

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

我认为这是因为这个聊天窗口。这是我的代码片段。!

[[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];
}

先谢谢。!

2 个答案:

答案 0 :(得分:1)

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

<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

其次使用此行显示ImagePicker: -

[self presentModalViewController:picker animated:YES];

替代方式: -

[self.view addSubview:imagePicker.cameraOverlayView]

答案 1 :(得分:1)

按如下方式更改方法声明

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

该方法将“CapturePhotoImage”称为CapturePhotoImage:

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