【发布时间】:2015-02-09 05:13:35
【问题描述】:
我有这样的视图控制器结构: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>'
这就是我尝试展示对话的方式:
-(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->@987654340 @->(调用shareWithLinkedIn方法)
【问题讨论】:
-
showShareWindow是做什么的?而closeWhiteView实际上关闭了testWindow? -
@gabbler
showShareWindow执行[testWindow makeKeyAndVisible]和closeWhiteView关闭UIWindow其中包含调用-(void)shareWithLinkedIn:(AVMSocNetButton*)sender方法的按钮。请参阅我的编辑以获取解释 -
你是如何关闭WhiteView并关闭窗口的?
-
@gabbler
-(void)closeWhiteView{ [socialWindow resignKeyWindow]; socialWindow.hidden = YES; socialWindow = nil; }效果很好。 -
我认为
testWindow.hidden = YES;会按预期工作,这是因为 testWindow 在前面并阻止了按钮的触摸事件,但是 textView 已经成为第一响应者,所以它是可编辑的.
标签: ios objective-c uitableview uinavigationcontroller slcomposeviewcontroller