2

从中选择图像后,我需要调用视图控制器imagePickerController,因此我使用了以下代码:

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

    imageEditorView = [[ImageEditorViewController alloc]initWithNibName:@"ImageEditorViewController" bundle:nil];
    imageEditorView.mainViewController = self;
    imageEditorView.imageBG = [info objectForKey:UIImagePickerControllerOriginalImage];

    [self presentViewController:imageEditorView animated:YES completion:nil];

}

但调试器给了我这个警告:

Warning: Attempt to present <ImageEditorViewController: 0xaa42320> on
     <ViewController: 0x9b58680> whose view is not in the window hierarchy!

没有礼物!

如果我 dissMiss 它首先调试器会给我这个错误:

 Warning: Attempt to present <ImageEditorViewController: 0xa913980> on
 <ViewController: 0x9b332a0> while a presentation is in progress

已编辑

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
    } else {
        self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil] autorelease];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
4

4 回答 4

4

使用以下代码,例如:

[self dismissViewControllerAnimated:YES completion:^{
   [self.parentViewController presentViewController:imageEditorView animated:YES completion:nil];
}];
于 2012-12-24T11:44:51.140 回答
1

更新:

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

    imageEditorView = [[ImageEditorViewController alloc]initWithNibName:@"ImageEditorViewController" bundle:nil];
    imageEditorView.mainViewController = self;
    imageEditorView.imageBG = [info objectForKey:UIImagePickerControllerOriginalImage];


    [self performSelector:@selector(presentPicture) withObject:nil afterDelay:2.0];
    [self dismissModalViewControllerAnimated:YES];

}


-(void)presentPicture 
{
     [self presentViewController:imageEditorView animated:YES completion:nil];
}
于 2012-12-24T11:31:29.717 回答
0

首先你必须关闭 UIImagePickerController 然后只有你可以使用 presentViewController 去另一个视图控制器。

您可以使用以下代码

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

[self dismissModalViewControllerAnimated:YES];
imageEditorView = [[ImageEditorViewController alloc]initWithNibName:@"ImageEditorViewController" bundle:nil];
imageEditorView.mainViewController = self;
imageEditorView.imageBG = [info objectForKey:UIImagePickerControllerOriginalImage];

[self presentViewController:imageEditorView animated:YES completion:nil];

}
于 2012-12-24T11:12:24.123 回答
0

我认为在你的AppDelegate你没有设置你rootViewControllerwindow。所以而不是添加subviewwindow制作rootViewController你的window.

另一件事可能是你的当前viewController实际上subview是另一个viewController

我的建议是放入self.window.rootViewController = yourMaincontroller 您的AppDelegate.

于 2012-12-24T11:12:28.077 回答