logo
Tags down

shadow

Alertview not called when no Internet access


By : Faith Ben
Date : September 16 2020, 03:00 AM
will be helpful for those in need The background queue is redundant because NSURLSession dispatches its tasks on a background thread anyway.
But you have to present the alert controller on the main thread
code :
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://www.websitethatdownloadsdata.com"] completionHandler:^(NSData *myData, NSURLResponse *response, NSError *error) {

   NSLog(@"Resp value from NSURL task: %@", response);
   NSLog(@"Error value from NSURL task: %@", error);

   if (error == nil) {

      NSLog(@"Downloading data...");

   } else {
      UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Network Problem" message:@"Cannot download data" preferredStyle:UIAlertControllerStyleAlert];
      UIAlertAction * actionOK = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         //Here Add Your Action
         abort();
      }];

      [alert addAction:actionOK];
      dispatch_async(dispatch_get_main_queue()) {
          [self presentViewController:alert animated:YES completion:nil];
      }
   }

}


Share : facebook icon twitter icon

alertView didDismissWithButtomIndex is not called after a click on the alertView's buttom


By : Trà Chanh
Date : March 29 2020, 07:55 AM
it helps some times didDismissWithButtonIndex is misspelled, you snuck an ‘m’ in there instead of ’n’.

Returning a BOOL value from alertview delegate method: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(


By : eric roman
Date : March 29 2020, 07:55 AM
it fixes the issue I added a tabbar controller on MainWindow.xib which is displaying 5 tabs and have the tab bar controller's delegate method: shouldSelectViewController in my app delegate which returns boolean value (YES or NO). , try this
in .h
code :
UIViewController *tmpController;
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
tmpController = viewController;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return NO;
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex) {
    self.tabBarController.selectedViewController = tmpController;
}
}

How to dismiss alertview in delegate function - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger


By : Caio Graco Rodrigues
Date : March 29 2020, 07:55 AM
will be helpful for those in need In my app, I need to dismiss the alertview when user click the button in alertview. I tried [alertView dismissWithClickedButtonIndex:-1 animated:NO];in my app, but it doesn't work. , Do nothing.

alertView didDismissWithButtonIndex never called


By : Imane K
Date : March 29 2020, 07:55 AM
Any of those help I think this an artifact of the fact that you are showing, then immediately dismissing the alert view in the same method -- you would never actually do this in a real app. If you create a property for the alert view, and then do the test like below, it works fine:
code :
- (IBAction)test:(id)sender {
    self.av  = [[UIAlertView alloc] initWithTitle:@"Encrypting File(s)" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [self.av show];
    [self performSelector:@selector(dismissAlertView) withObject:nil afterDelay:1];
}


-(void)dismissAlertView {
    [self.av dismissWithClickedButtonIndex:-1 animated:YES];
}

- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"willDISMIS");
}

- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    NSLog(@"didDISMIS");
}

Alertview Void Alert3 clickedButtonAtIndex is not called


By : user3505998
Date : March 29 2020, 07:55 AM
will help you I think your mistake is on the alertview delegate method's name.
You had to use:
code :
- (void)alertView:(UIAlertView *)myAlert3 didDismissWithButtonIndex:(NSInteger)buttonIndex
- (void)myAlert3:(UIAlertView *)myAlert3 didDismissWithButtonIndex:(NSInteger)buttonIndex
Related Posts Related Posts :
shadow
Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk