Reputation: 63
I have added a UIAlterController to my view. IT triggers fine, looks fine, and has its action, however tapping the Cancel action does nothing, it doesnt run any code, even if i add a block it wont execute it, it just doesnt seem to recognise the tap at all.
The code looks fine to me, so is there some other cause?
- (void)connectionFailed:(NSString *)title {
NSString *message = nil;
if ([title isEqualToString:NSLocalizedString(@"Connection Refused", @"connection Refused")]) {
message = NSLocalizedString(@"You do not have permission to use this console", @"incorrect permissions message");
}
else {
message = NSLocalizedString(@"Connection Failed", @"connection failed error message");
}
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
});
Edit: it appears the issue is down to view leaks causing problems, not sure of the fix but here is the breakdown in debugging:
Upvotes: 1
Views: 355
Reputation: 884
- (void)connectionFailed:(NSString *)title {
NSString *message = nil;
if ([title isEqualToString:NSLocalizedString(@"Connection Refused", @"connection Refused")]) {
message = NSLocalizedString(@"You do not have permission to use this console", @"incorrect permissions message");
}
else {
message = NSLocalizedString(@"Connection Failed", @"connection failed error message");
}
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style: UIAlertActionStyleCancel
handler:nil];
[alertController addAction:cancelAction];
[self presentViewController:alertController animated:YES completion:nil];
});
just edited your cancel button alert style....
Upvotes: 1
Reputation: 1334
Try this:
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
//your code here ...
}];
Upvotes: 1
Reputation: 989
Use this:
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:nil];
Change UIAlertActionStyleDefault
to UIAlertActionStyleCancel
Upvotes: 1
Reputation: 8322
Try this :
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel"
UIAlertActionStyleDefault
handler:nil];
Upvotes: 0