1

我有这样的视图控制器的结构为:UINavigationController(root view controller)->UIViewController。在我的UIViewController我有UITableView动态细胞。在每个单元格中都有“共享”按钮,其呈现全屏UIWindow。这个UIWindow包含一个UIView社交网络按钮,每个按钮都必须显示共享对话框,一切都正常,只适用于社交网络框架或库的按钮,但我有一个按钮,必须提供自定义共享对话框。当我按下它我的应用程序有以下错误而崩溃:*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'adding a root view controller <REComposeViewController: 0x7f9e8b416260> as a child of view controller:<AVMNavCon: 0x7f9e887540f0>'当呈现视图控制器时UIViewControllerHierarchyInconsistency

这就是我试图表明我的对话:

-(void)shareWithLinkedIn:(AVMSocNetButton*)sender{ 
[self closeWhiteView]; // close UIWindow with social network buttons 
REComposeViewController *composeViewController = [[REComposeViewController alloc] init]; // define and initialize custom share dialog 
composeViewController.title = @"Social"; 
composeViewController.hasAttachment = YES; 
composeViewController.attachmentImage = sender.shareImage; 
composeViewController.text = [NSString stringWithFormat:@"Share text"]; 
testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 74, SCREEN_WIDTH-10, SCREEN_HEIGHT/2)]; 
testWindow.windowLevel = UIWindowLevelStatusBar; 
testWindow.hidden = NO; 

testWindow.rootViewController = composeViewController; 
[composeViewController presentFromRootViewController]; 

[self performSelector:@selector(showShareWindow) withObject:nil afterDelay:1]; 
} 

正如每个人都可以在这里看到我用另外一个UIWindow(testWindow)。这是因为如果我将显示我的对话框没有UIWindow我的UIViewController将消失,我会看到黑色背景上的共享对话框。 然后,如果我评论行testWindow.rootViewController = composeViewController;我会看到我的共享对话框,但没有任何交互(我无法触摸屏幕上的任何按钮) 我应该如何展示我的对话框并避免此错误?

编辑:

完整层次是:UINavigationController - >UIViewController - >UITableView - >UITableViewCell - >UIButton - >(呼叫 “WhiteView” UIWindow) - >UIWindow - >UIButton - >(调用shareWithLinkedIn方法)

+0

'showShareWindow'的作用是什么?和'closeWhiteView'实际上关闭了testWindow? – gabbler 2015-02-12 12:12:55

+0

@gabbler'showShareWindow'确实调用' - (void)shareWithLinkedIn:(AVMSocNetButton *)sender'方法调用'[testWindow makeKeyAndVisible]'和'closeWhiteView'关闭'UIWindow'。请参阅我的编辑以获得解释 – vendettacore 2015-02-12 12:21:09

+0

您是如何关闭WhiteView并关闭窗口的? – gabbler 2015-02-12 12:32:11

回答

1

您不应该尝试使用窗口的根视图控制器作为模式。如果要使用窗口实现此转换,请使用背景为空的UIViewController作为rootViewController,然后将composeViewController作为模式呈现。

你可以在不使用Windows的情况下完成你想要做的事情。例如,在iOS 8上,对于您的composeViewController,使用UIModalPresentationOverFullScreen作为modalPresentationStyle,并将其作为当前控制器的模式呈现。再次,你需要一个透明的容器视图来做到这一点,但它比引入另一个窗口更清洁。在iOS 7上,您需要使用UIModalPresentationCustom(默认情况下效果与UIModalPresentationOverFullScreen相同)

0

所有你想要做的是提出对根视图控制器的顶部您的VC:

- (void)shareWithLinkedIn:(AVMSocNetButton*)sender{ 
    REComposeViewController *composeViewController = [[REComposeViewController alloc] init]; // define and initialize custom share dialog 
    composeViewController.title = @"Social"; 
    composeViewController.hasAttachment = YES; 
    composeViewController.attachmentImage = sender.shareImage; 
    composeViewController.text = [NSString stringWithFormat:@"Share text"]; 

    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:composeViewController animated:YES completion:nil]; 
} 
+0

它不起作用。它使屏幕变黑,虽然'NSLog'显示composeViewController存在的消息:'composeViewController ' – vendettacore 2015-02-12 12:45:03

+0

@vendettacore,什么是'REComposeViewController'呢? – orkenstein 2015-02-12 12:53:00

+0

https://github.com/romaonthego/REComposeViewController这里是完整的解释。所以我试图做到以下几点:'[[[[UIApplication sharedApplication] keyWindow] rootViewController] addChildViewController:composeViewController]; [[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:composeViewController animated:YES completion:nil];它显示我想要什么,但它杀死了之前的UIViewController – vendettacore 2015-02-12 12:55:53