Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIAlertController未定位在childViewController上,而是显示在parentViewController上_Ios_Objective C_Childviewcontroller_Parentviewcontroller_Childviews - Fatal编程技术网

Ios UIAlertController未定位在childViewController上,而是显示在parentViewController上

Ios UIAlertController未定位在childViewController上,而是显示在parentViewController上,ios,objective-c,childviewcontroller,parentviewcontroller,childviews,Ios,Objective C,Childviewcontroller,Parentviewcontroller,Childviews,我已经创建了一个左菜单抽屉,并将其添加为子视图控制器。在左侧菜单抽屉中,我有一个注销按钮,该按钮应显示UIAlertController。我遇到的挑战是UIAlertController显示在父视图的子视图(左抽屉)后面 //ParentVC //adding childVC DrawerViewController *menuController = [[DrawerViewController alloc] init]; [self addChildViewController:m

我已经创建了一个左菜单抽屉,并将其添加为子视图控制器。在左侧菜单抽屉中,我有一个注销按钮,该按钮应显示UIAlertController。我遇到的挑战是UIAlertController显示在父视图的子视图(左抽屉)后面

//ParentVC 
//adding childVC
  DrawerViewController *menuController = [[DrawerViewController alloc] init];
  [self addChildViewController:menuController];
  [self.view addSubview:menuController.view];
  [menuController didMoveToParentViewController:self];
  [[[[UIApplication sharedApplication] delegate] window] addSubview:menuController.view];
  menuController.definesPresentationContext = YES;

//displaying childVC from parentVC
  [UIView animateWithDuration:0.3 animations:^{
    [menuController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view setFrame:CGRectMake(self.view.frame.size.width*0.7, 0, self.view.frame.size.width, self.view.frame.size.height)];

  }];


//ChildVC
//logout action
-(void) logOutButtonListener:(UIButton *) sender{
NSLog(@"logOutButtonListener");

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Logout" message:@"Are you sure you want to logout?" preferredStyle:UIAlertControllerStyleAlert ];

UIAlertAction* noButton = [UIAlertAction actionWithTitle:@"no" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:noButton];

UIAlertAction* yesButton = [UIAlertAction actionWithTitle:@"yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
    //logout logic
}];
[alert addAction:yesButton];

[self presentViewController:alert animated:YES completion:nil];
}

我想要的是在子视图控制器的顶部显示UIAlertController。

问题是您正在将menuController.view添加到堆栈中所有其他ViewController(包括警报控制器)顶部的主窗口中。如果您希望菜单位于所有内容之上,但仍位于警报控制器之下,请将其添加到视图树中的某个位置,而不是窗口(请参阅当前VC或堆栈中更高的位置),这样它就不会出现在警报的顶部。

这基本上起到了作用,我将menuController.view添加到了最顶部的视图控制器视图中