1

I am new to iOS Programming, I have Implemented UITableViewController and getting that tableViewController design on my homepage like a popup, Backside I added Blur effect between homepage and tableViewController. Both blur effect view and UITableView are added as subviews in main screen.

Here is my problem:

When I'm validating UITextfields of tableViewController, alertController is appearing backside of blur effect and tableViewController, I need that over tableViewController.

How can I get??

I used below Code for blur effect and 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];

I used below code to show alert:

 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];
 });
Shubam Gupta
  • 61
  • 1
  • 11

2 Answers2

5

Try this

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];
Prajnaranjan Das
  • 1,378
  • 1
  • 9
  • 26
  • Hello Das,One more doubt I have implemented Touchid for fingerprint, that alert also have a same issues ,how would I get over my view. – Shubam Gupta Feb 16 '18 at 04:52
  • @Shubam Gupta. Can you please give some more description about your issue regarding AlertController with touchid. – Prajnaranjan Das Feb 16 '18 at 08:41
0

you can present your alertController on child controller like:

[viewaccept presentViewController:alert animated:YES completion:nil];
Nisar Ahmad
  • 885
  • 1
  • 10
  • 25
  • I have tried but still I am getting alert, on backside of uitabeviewcontroller – Shubam Gupta Feb 15 '18 at 10:15
  • if you are adding your tableViewController as a child controller than present alertViewController on child controller instead of parent. I mean instead of : [self presentViewController:alert animated:YES completion:nil]; use: [viewaccept presentViewController:alert animated:YES completion:nil]; – Nisar Ahmad Feb 15 '18 at 10:23
  • @ShubamGupta - get the top VC and present your alert – Anbu.Karthik Feb 15 '18 at 10:38
  • viewaccept code in homepage.m and alertviewcontroller is appearing is smoother file like acceptviewcontroller.m – Shubam Gupta Feb 15 '18 at 10:50
  • Than you can get the topViewController from the navigation stack or window and present your alert on this – Nisar Ahmad Feb 15 '18 at 11:56
  • @ShubamGupta [Use this](https://stackoverflow.com/questions/6131205/iphone-how-to-find-topmost-view-controller) to get topViewController & show the UIAlertController on that topViewController. – Rocky Feb 15 '18 at 13:43