0

我正在使用presentViewController:imagePickerController來顯示UIImagePickerController。由於某種原因,當我最終解散那個控制器時,我的原始導航控制器失去了堆棧,我的應用程序又回到了根視圖控制器。presentViewController:imagePickerController彈出我的導航控制器?

我記錄self.navigationController.viewControllers,我可以看到,我運行presentViewController:imagePickerController行後,我的導航控制器鬆動除根控制器以外的所有控制器。

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; 
imagePickerController.sourceType = sourceType; 
imagePickerController.delegate = self; 
imagePickerController.navigationBarHidden = YES; 

self.imagePickerController = imagePickerController; 

DLog(@"self.navigationController:%@",self.navigationController.viewControllers); 
[self.navigationController presentViewController:imagePickerController animated:YES completion:^{ 
     DLog(@" after presenting self.navigationController:%@",self.navigationController.viewControllers); 

    }]; 

////關閉它

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    DLog(@"self.navigationController:%@",self.navigationController.viewControllers); 
    [self.navigationController dismissViewControllerAnimated:YES completion:^{ 

    }]; 
} 

/////凡我NC設置

OFMainViewController *mainController = [[OFMainViewController alloc]init]; 
    mainController.managedObjectContext = self.managedObjectContext; 
    navigationController = [[UINavigationController alloc]initWithRootViewController:mainController]; 
[self.window setRootViewController:navigationController]; 
+0

是什麼,作爲導航控制器的代表?你是否明確地改變了導航堆棧的位置? – Wain

回答

1

而不是使用self.navigationController使用自兩個解聘和調用imagepickerviewcontroller。

0

您應該在self上提供imagePickeController而不是self.navigationController

[self presentViewController:imagePickerController animated:YES completion:^{ 
    DLog(@" after presenting self:%@",self.navigationController.viewControllers); 

}]; 

而且dissmiss它相應:

////Closing it 

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
    DLog(@"self.navigationController:%@",self.navigationController.viewControllers); 
    [self dismissViewControllerAnimated:YES completion:^{ 

    }]; 
} 
相關問題