SDCAlertView dismissWithClickedButtonIndex:animated:使UIView无效

时间:2014-06-04 20:42:33

标签: ios objective-c sdcalertview

我正在使用SDCAlertView的pod,找到here来实现一系列带有图像和其他功能的警报消息。警报以音频事件为中心(即插入或移除耳机),有时需要在没有点击警报按钮的情况下被解除。

我致电dismissWithClickedButtonIndex: animated:后出现问题。电话本身似乎工作正常,但一旦警报消失,下一个UIView就会变得没有反应。

此回调中发生 dismissWithClickedButtonIndex: animated: 调用的一个实例:

- (void) audioRouteChangeListener: (NSNotification *)notification {
    // Initiallize dictionary with notification and grab route change reason
    NSDictionary *interuptionDict = notification.userInfo;
    NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];

    switch (routeChangeReason) {
        // Sensor inserted
        case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
            // Dismiss alert if any and begin collection
            if (self.sensorAlert != nil) {
                [self.sensorAlert dismissWithClickedButtonIndex:0 animated:YES];
                self.sensorAlert = nil;
            }

            // **** DEBUG ****
            NSLog(@"Sensor INSERTED");
            break;

        default:
            NSLog(@"Blowing it in- audioRouteChangeListener with route change reason: %ld", (long)routeChangeReason);
            break;
   }
}

我添加了alertView处理程序didDismissWithButtonIndex:,并确认解雇调用正在进行:

- (void) alertView:(SDCAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
        case 0:
            // Checking for dismiss
            NSLog(@"Made it to standard dismiss\n");
            break;

        default:
            NSLog(@"Uncaught dismiss\n");
            break;
    }
}

SDCAlertView实例是NSObject子类的一部分,而不是UIViewController,我猜这可能是问题的原因,但我认为clickedButtonAtIndex调用会产生相同的效果,但它会不

我像这样设置了SDCAlertView:

// Set up alert View for a disconnected sensor
self.sensorAlert = [[SDCAlertView alloc]
     initWithTitle:@"No Sensor"
     message:@"Please insert the GSF sensor and try again."
     delegate:self
     cancelButtonTitle:nil
     otherButtonTitles:@"Try Again", nil];

     [alertImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
     [self.sensorAlert.contentView addSubview:alertImageView];
     [alertImageView sdc_horizontallyCenterInSuperview];
     [self.sensorAlert.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[alertImageView]|"
                                                                                             options:0
                                                                                             metrics:nil
                                                                                               views:NSDictionaryOfVariableBindings(alertImageView)]];

非常感谢任何帮助解决这个问题。

0 个答案:

没有答案
相关问题