1

我有一個故事板,看起來像這樣:試圖提出有關VC,其觀點是不是在窗口層次模式的VC

Storyboard

這是它是如何工作的:InitialSlidingViewController實例導航VC爲topViewController如下其.m文件:

-(void)viewDidLoad { 
    [super viewDidLoad]; 

    self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Navigation"]; 

} 

後導航VC被實例化,它創建的基本功能,並設置爲underLeftVC。這是使用ECSlidingViewController。這會創建一個使用平移手勢的滑動菜單,與Facebook類似。

NavigationVC的rootVC是我的ItemsCDTVC。當我點擊+按鈕時,它會彈出一張操作表,讓我從相機拍攝照片或從照片庫中進行選擇。但是,我希望它模式地繼續到ManageItemVC並設置我剛剛選擇/拍攝到它的UIImageView的圖片。當我嘗試到現在,它引發以下錯誤:

Warning: Attempt to present <ManageItemViewController: 0x81d52a0> on <InitialSlidingViewController: 0x8122ce0> whose view is not in the window hierarchy! 

這是真的,因爲InitialSlidingVC是不是在屏幕上,ItemCDTVC是,但我要如何解決這個問題?

我已經在我的故事板中設置了模式類型segue,其底部的靈活空間中有一個標識符(當點擊時,它沒有任何操作,所以我選擇了創建視覺輪廓)。這是我在項目CDTVC中的segue代碼:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    // let's get the edited image 
    UIImage *image = info[UIImagePickerControllerEditedImage]; 
    // but if for some reason we disable editing in the future, this is our safeguard 
    if(!image) image = info[UIImagePickerControllerOriginalImage]; 
    if(image) { 
     self.pictureImageView.image = image; 
     [self performSegueWithIdentifier:@"addItemSegue" sender:self]; 
    } 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if([segue.identifier isEqualToString:@"addItemSegue"]){ 
     ManageItemViewController *manageItemVC = (ManageItemViewController *)[segue destinationViewController]; 
     manageItemVC.pictureImageView = self.pictureImageView; 
    } 
} 

嘗試呈現模態VC時失敗。

回答

5

固定的,我不得不這樣做的唯一事情就是嘗試執行之前賽格瑞駁回imagePickerController,像這樣:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    // let's get the edited image 
    UIImage *image = info[UIImagePickerControllerEditedImage]; 
    // but if for some reason we disable editing in the future, this is our safeguard 
    if(!image) image = info[UIImagePickerControllerOriginalImage]; 
    if(image) { 
     self.pictureImage = image; 
     [self dismissViewControllerAnimated:NO completion:^{ 
      [self performSegueWithIdentifier:@"addItemSegue" sender:self]; 
     }]; 
    } 
} 
+0

優秀。不僅在解僱後,而且在完成塊中。 – Camus 2014-02-19 01:29:13

相關問題