0

I have a simple view with a button linked with "showAlert" method. When I click on this button, it displays a UIAlertView.

Before, with ios 6, I was using the following code to disable a UIAlertView button :

- (IBAction)showAlert:(id)sender
{
    myAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"Retour" otherButtonTitles:@"Button1", @"Button2", @"Button3", @"Button4", nil];
    [myAlert show];

    for(UIView *aView in myAlert.subviews)
    {
        if ([[[aView class] description] isEqualToString:@"UIAlertButton"])
        {
            UIButton *aButton = (UIButton *)aView;
            if ([aButton.titleLabel.text isEqualToString:@"Button2"])
                aButton.enabled = NO;
        }
    }
}

Now, with ios 7, it does not work... Why ?

Jonathan F.
  • 2,357
  • 4
  • 26
  • 44

3 Answers3

1

Since iOS7 it's not possible to add or manipulate the subviews or a UIAlertView, you need to create your own, sorry.

Subclass UIView to create your own UIAlertView or use a 3rd party library.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
0

Adding a subview to UIAlertView is not possible from iOS 7.

The only way is to go for a custom UIView subclass which can act as UIAlertView.

Github and this answer may get you a solution.

Community
  • 1
  • 1
iOS
  • 3,526
  • 3
  • 37
  • 82
0

You can disable 1st other Button of UIAlertView using delegate method

-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    return NO;
}

works in ios 7 also.

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
  • Thanks Viruss, but I need to be able to disable sometimes the first button, sometimes the second, or some other buttons, according to its name. – Jonathan F. Oct 10 '13 at 14:40
  • @Erzékiel: no you can only disable first btn with this method. – Toseef Khilji Oct 11 '13 at 03:52
  • @Virussmca i want also change the title of first button how can i do this please suggesst some things which will work on ios 6 and as well with ios 7 – user100 Aug 31 '14 at 11:03