您好我是开发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];
}
先谢谢。!
答案 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];