Domanda

For some reason the SDCAlertView clickButtonAtIndex callback from the SDCAlertView POD (seen in the code block below) is never being called. The SDCAlertView shows but after I've selected a button on my alert no callback is invoked. Apples alertView works with this callback just fine. I've imported <SDCAlertView.h> and <UIView+SDCAutoLayout.h> into my classes header file and made sure to open the workspace no the project so the POD is accessible.

Anyone using SDCAlertView run into this problem or see something I'm doing incorrectly?

- (void)alertView:(SDCAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; {
        // *** NEVER MAKES IT IN HERE ***
        switch (buttonIndex) {
        case 0:
            NSLog(@"alertView: Cancel");
            break;
        case 1:
            NSLog(@"alertView: OK");
            break;
        default:
            NSLog(@"Blowing It: Alert not handled");
            break;
    }
}

Below is the setup of one of the SDCAlertView in my project which is declared in my MainViewController.m file. I'm adding a slider to adjust volume for a headset.

    // Setup Slider for Alert View
    UISlider *volumeSlider = [[UISlider alloc] initWithFrame:CGRectMake(20, 50, 200, 200)];
    volumeSlider.maximumValue = 10.0;
    volumeSlider.minimumValue = 1.0;
    [volumeSlider addTarget:self action:@selector(sliderHandler:) forControlEvents:UIControlEventValueChanged];

    // Setup Alert View
    SDCAlertView *noHeadsetAlertView =
               [[SDCAlertView alloc]
                initWithTitle:@"No Headset"
                message:@"You need a headset you fool!"
                delegate:nil
                cancelButtonTitle:nil
                otherButtonTitles:@"Cancel", @"Use Mic", nil];
    [volumeSlider setTranslatesAutoresizingMaskIntoConstraints:NO];
    [noHeadsetAlertView.contentView addSubview:volumeSlider];

    [volumeSlider sdc_pinWidthToWidthOfView:noHeadsetAlertView.contentView offset: -20];
    [volumeSlider sdc_horizontallyCenterInSuperview];

    [noHeadsetAlertView.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[volumeSlider]|"
                                                                              options:0
                                                                              metrics:nil
                                                                                views:NSDictionaryOfVariableBindings(volumeSlider)]];

    [noHeadsetAlertView show];

The SDCAlertView project can be found on GitHub.

È stato utile?

Soluzione

You're not setting a delegate in the initialization of the alert. Change it from nil to self and the method should get called.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top