2013-04-28 36 views
1

我正在学习如何使用情节提要处理视图控制器层次结构。我有2个ViewController:cwViewController类型的根(我知道下面是'self')和第二个类型的WorkspaceViewController。我正在“尝试在演示进行中呈现!”作为这个代码的结果。简单视图控制器开关原因:尝试在演示文稿正在进行时呈现

- (IBAction)nextView { 
    WorkspaceViewController *workspace = [[WorkspaceViewController alloc] initWithNibName:nil bundle:nil]; 
    [self presentViewController:workspace animated:YES completion:NULL]; } 

答案How to present view controller properly?是可以适用这一点,但因为我不是来回切换的VC之间,我只是提出一个,然后贬显示无法很好地适应这种情况最接近的答案原本的。

于是,我试图驳回呈现前一秒当前,由于一些答案建议,像这样:

[self dismissViewControllerAnimated:NO completion:nil]; 
[self presentViewController:workspace animated:YES completion:NULL]; 

但是,这只是让我一个额外的警告:尝试从视图控制器解雇而呈现或解雇正在进行中!

做一些其他的研究,我看到了类似的问题,通过加入一个块

[self dismissViewControllerAnimated:YES...] 

解决,但因为之前我甚至到一个地步,我认为这种解雇方式出现我的警告,不帮助这里。关于如何处理视图的顺序和层次结构的进一步知识将是一个很大的帮助。非常感谢。

+0

首先,如果你使用的是故事板,你应该在alloc初始化WorkspaceViewController。这不是从故事板实例化视图控制器的方式。故事板上是否有任何插曲? – rdelmar 2013-04-28 05:37:00

+0

发生此问题是因为您快速点击nextView多个按钮吗? – user523234 2013-04-28 09:22:32

+0

rdelmar,不,我还没有使用过segues。随意指出我在正确的方向。 user523234这发生在第一次调用下一个视图时(它是从通知观察者调用的)。谢谢大家。 – roro 2013-04-28 21:43:21

回答

0

尝试

[self presentModalViewController:workspace animated:YES]; 
if (![[self modalViewController] isBeingPresented]) { 
     [self dismissModalViewControllerAnimated:YES]; 
} 
2

你创建一个从按钮SEGUE你WorkSpaceViewController?如果是这样,您可能会尝试两次显示WorkSpaceView - 一次选择按钮并从cwViewController中一次。要消除该错误,请将按钮上的Segue从WorkSpaceViewController中删除,然后重新创建segue - 这次是在cwViewController和WorkSpaceViewController之间进行的。这应该照顾它。

2
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

// TODO: make this all threaded? 
// crop the image to the bounds provided 
img = [info objectForKey:UIImagePickerControllerOriginalImage]; 
NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]); 

// save the image, only if it's a newly taken image: 
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) { 
    UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil); 
} 

// self.image_View.image = img; 
// self.image_View.contentMode = UIViewContentModeScaleAspectFit; 

NSLog(@"Picker has returned"); 
[self dismissViewControllerAnimated:YES 
         completion:^{ 
          ModalViewController *sampleView = [[ModalViewController alloc] init]; 
          [self presentModalViewController:sampleView animated:YES]; 
         }]; 
} 
相关问题