加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – SDCAlertView回调clickButtonAtIndex未在运行时i

发布时间:2020-12-16 07:07:55 所属栏目:百科 来源:网络整理
导读:由于某种原因,从SDCAlertView POD(见下面的代码块中)的SDCAlertView clickButtonAtIndex回调永远不会被调用. SDCAlertView显示但在我在警报上选择了一个按钮后,没有调用回调.苹果alertView可以正常使用这个回调.我已导入 SDCAlertView.h和 UIView SDCAutoLay
由于某种原因,从SDCAlertView POD(见下面的代码块中)的SDCAlertView clickButtonAtIndex回调永远不会被调用. SDCAlertView显示但在我在警报上选择了一个按钮后,没有调用回调.苹果alertView可以正常使用这个回调.我已导入< SDCAlertView.h>和< UIView SDCAutoLayout.h>进入我的类头文件,并确保打开工作区没有项目,以便可以访问POD.

任何使用SDCAlertView的人遇到这个问题或看到我做错了什么?

- (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;
    }
}

下面是我的项目中SDCAlertView之一的设置,它在我的MainViewController.m文件中声明.我正在添加一个滑块来调整耳机的音量.

// 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];

SDCAlertView项目可以在GitHub上找到.

解决方法

您没有在警报初始化中设置委托.将它从nil更改为self,并调用该方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读