2

嗨,我很新開發iOS應用程序,請幫助我。我正在使用UIImagePicker捕獲圖像時遇到問題。我已經將臀部暴徒應用程序整合到我們的應用程序中捕捉圖像無法正常工作。?

在那個窗口中,我想顯示一個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

是圖片選擇器顯示?或它正在崩潰 – Vizllx

+0

謝謝你的回覆..!沒有它沒有顯示圖像選擇器,我在設備上測試過,所以它不會崩潰。我認爲我使用hipmob控制器,我添加按鈕,所以它不導航imagePickerView –

+0

你被添加self.view添加子視圖viewObjForVehicleDetails –

回答

1

首先確保你使用以下的委託在您的視圖控制器

<UINavigationControllerDelegate, UIImagePickerControllerDelegate> 

其次使用此行來顯示ImagePicker: -

[self presentModalViewController:picker animated:YES]; 

替代方式: -

[self.view addSubview:imagePicker.cameraOverlayView] 
+0

是的,我已經給了這些委託方法,我也給[自我presentModalViewController:選擇器動畫:是];到我的代碼,即使沒有變化。它顯示相同的消息[其視圖不在窗口層次!] –

+0

請幫我@Vizllx –

+0

@ AppDeveloper-檢查替代答案。 – Vizllx

1

更改方法聲明如下

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

而且方法調用 「CapturePhotoImage」 爲CapturePhotoImage:

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

沒有它沒有顯示圖像選擇器,並拋出一個消息作爲其視圖不在窗口層次結構! –