Ios 如何在目标C中通过UIView获得UIAlertController?

Ios 如何在目标C中通过UIView获得UIAlertController?,ios,objective-c,uialertcontroller,addsubview,subviews,Ios,Objective C,Uialertcontroller,Addsubview,Subviews,我不熟悉iOS编程, 我已经实现了UITableViewController,并将tableViewController设计像弹出窗口一样显示在我的主页上, 背面我在主页和tableViewController之间添加了模糊效果。 模糊效果视图和UITableView都作为子视图添加到主屏幕中 这是我的问题: 当我验证tableViewController的UITextfields时,alertController出现在模糊效果和tableViewController的背面,我需要它覆盖tabl

我不熟悉iOS编程, 我已经实现了UITableViewController,并将tableViewController设计像弹出窗口一样显示在我的主页上, 背面我在主页和tableViewController之间添加了模糊效果。 模糊效果视图和UITableView都作为子视图添加到主屏幕中

这是我的问题:

当我验证tableViewController的UITextfields时,alertController出现在模糊效果和tableViewController的背面,我需要它覆盖tableViewController

我怎样才能得到???

我在模糊效果和tableView中使用了以下代码:

UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];        
visualEffectView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[[UIApplication sharedApplication].keyWindow addSubview:visualEffectView];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
viewaccept = (AcceptViewController *)[storyboard instantiateViewControllerWithIdentifier:@"AcceptViewController"];
[viewaccept willMoveToParentViewController:self];

CGRect screen = [[UIScreen mainScreen] bounds];
CGRect newFrame = CGRectMake(0,screen.size.height/4, self.view.frame.size.width, 350);
UIEdgeInsets insets = UIEdgeInsetsMake(0,10,0,10);

viewaccept.view.frame = UIEdgeInsetsInsetRect(newFrame,insets);
CGRect splitframe = viewaccept.view.frame;
[viewaccept.view setFrame:splitframe];
[[UIApplication sharedApplication].keyWindow addSubview:viewaccept.view];
[self addChildViewController:viewaccept];
[viewaccept didMoveToParentViewController:self];
我使用以下代码来显示警报:

 NSString *message = @"Email Id is already registered";
 UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
 [self presentViewController:alert animated:YES completion:nil];

 int duration = 3; // duration in seconds
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, duration * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
     [alert dismissViewControllerAnimated:YES completion:nil];
 });

您可以在子控制器上显示alertController,如:

[viewaccept presentViewController:alert animated:YES completion:nil];

您可以在子控制器上显示alertController,如:

[viewaccept presentViewController:alert animated:YES completion:nil];
试试这个

UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
topWindow.rootViewController = [UIViewController new];
topWindow.windowLevel = UIWindowLevelAlert + 1;

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Your Message" preferredStyle:UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK",@"confirm") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  // continue your work

// important to hide the window after work completed.
// this also keeps a reference to the window until the action is invoked.
topWindow.hidden = YES;
}]];

[topWindow makeKeyAndVisible];
[topWindow.rootViewController presentViewController:alert animated:YES completion:nil];
试试这个

UIWindow* topWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
topWindow.rootViewController = [UIViewController new];
topWindow.windowLevel = UIWindowLevelAlert + 1;

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Your Message" preferredStyle:UIAlertControllerStyleAlert];

[alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK",@"confirm") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  // continue your work

// important to hide the window after work completed.
// this also keeps a reference to the window until the action is invoked.
topWindow.hidden = YES;
}]];

[topWindow makeKeyAndVisible];
[topWindow.rootViewController presentViewController:alert animated:YES completion:nil];


你试过什么?共享您的代码尝试以下代码:[self.view将子视图带到前台:yourAlertController.view];我已经更新了我的代码。在当前显示的
UIViewController
上显示
UIAlertController
,即
viewaccept
。您尝试了什么?共享您的代码尝试以下代码:[self.view将子视图带到前台:yourAlertController.view];我已经更新了我的代码。在当前显示的
UIViewController
上显示
UIAlertController
,即
viewaccept
。我已经尝试了,但仍然收到了警报,在UITableViewController的背面,如果要将tableViewController添加为子控制器,则在子控制器而不是父控制器上显示alertViewController。我的意思是代替:[自我呈现视图控制器:警报动画:是完成:无];用法:[viewaccept presentViewController:警报动画:是完成:无]@ShubamGupta-获取顶级VC并在主页中显示您的alertviewaccept代码。m和alertviewcontroller显示的是更平滑的文件,如acceptviewcontroller.m,您可以从导航堆栈或窗口获取topViewController并显示此警报我已经尝试过,但仍然收到警报,在UITableViewController的背面,如果要将tableViewController添加为子控制器,则在子控制器而不是父控制器上显示alertViewController。我的意思是代替:[自我呈现视图控制器:警报动画:是完成:无];用法:[viewaccept presentViewController:警报动画:是完成:无]@ShubamGupta-获取顶级VC并在主页中显示您的alertviewaccept代码。m和alertviewcontroller显示的是更平滑的文件,如acceptviewcontroller.m。与您可以从导航堆栈或窗口获取topViewController并在此上显示您的警报相比,Hello Das,还有一个疑问,我已经为指纹实现了Touchid,那个警报也有同样的问题,我该如何克服我的观点。@Shubam Gupta。请您详细描述一下关于使用touchid的AlertController的问题。您好,Das,还有一个疑问是我没有为指纹实现touchid,该警报也有同样的问题,我如何克服我的观点。@Shubam Gupta。请您详细描述一下关于使用touchid的AlertController的问题。