Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c `NSNotification响应中未触发UIAlertController`_Objective C_Nsnotificationcenter_Uialertcontroller_Nsnotifications_Presentviewcontroller - Fatal编程技术网

Objective c `NSNotification响应中未触发UIAlertController`

Objective c `NSNotification响应中未触发UIAlertController`,objective-c,nsnotificationcenter,uialertcontroller,nsnotifications,presentviewcontroller,Objective C,Nsnotificationcenter,Uialertcontroller,Nsnotifications,Presentviewcontroller,这是我的AlertView代码: - (void)initializeAlertControllerForOneButtonWithTitle:(NSString *)title withMessage:(NSString *)msg withYesButtonTitle:(NSString *)yesButtonTitle withYesButtonAction:(id)yesButtonAction { UIAlertController * alert = [UIAlertCont

这是我的
AlertView
代码:

- (void)initializeAlertControllerForOneButtonWithTitle:(NSString *)title withMessage:(NSString *)msg withYesButtonTitle:(NSString *)yesButtonTitle withYesButtonAction:(id)yesButtonAction
{
    UIAlertController * alert = [UIAlertController
                                 alertControllerWithTitle:title
                                 message:msg
                                 preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* yesBtn = [UIAlertAction
                             actionWithTitle:yesButtonTitle
                             style:UIAlertActionStyleDefault
                             handler:^(UIAlertAction * action) {
                                 if (self.activityIndicator.animating) {
                                     [self.activityIndicator stopAnimating];
                                 }

                                 if ([title isEqualToString:@"Wrong Password!"]) {
                                     self.editTextField.text = @"";
                                     [self.editTextField becomeFirstResponder];
                                 }
                             }];

    [alert addAction:yesBtn];

    [self presentViewController:alert animated:YES completion:nil];
}
我正试图在我的
NSNotificatoin Response
方法中触发此警报。我的
通知响应
代码:

- (void)receiveSMSVerificationResponse:(NSNotification *)notification
{
    SMSVerificationDigitClassModel *smsVerificationDigitClassModel = [[SMSVerificationDigitClassModel alloc] init];
    smsVerificationDigitClassModel = [notification object];

    if (smsVerificationDigitClassModel.viewControllerName == ViewControllerNameProfileInfoEditViewController) {

        if ([self alreadyRegisteredPhoneNumber:smsVerificationDigitClassModel.phoneNumber] == YES) {
            NSLog(@"jogajog");
            [self initializeAlertControllerForOneButtonWithTitle:@"Already Registered!" withMessage:kAlreadyRegisteredPhoneNumberMSGForChangePhoneNumber withYesButtonTitle:@"Ok" withYesButtonAction:nil];

        } else {
            if ([AdditionalClasses internetConnectionCheck] == YES) {
                self.userModelClass.phone_number = smsVerificationDigitClassModel.phoneNumber;
                [self updateUserModel:self.userModelClass];
            } else {
                [self noInternetConnectionAlert];
            }
        }
        //Check if that phone number is already used
        // udate phone numner in server
        // update phone number in core data
        //[self goToSignUpViewControllerWithPhoneNumber:smsVerificationDigitClassModel.phoneNumber];
    }
}
我从断点开始检查它,这一行
[自初始化ErtControllerforoneButtonWithTitle:@“已注册!”并显示消息:KalReadyRegisteredPhoneNumber用于更改电话号码withYesButtonTitle:@“Ok”withYesButtonAction:nil]
实际上正在调用,但警报视图没有弹出。它说:

“警告:尝试显示不在窗口层次结构中的视图!”

我已尝试添加通知观察者方法:

- (void)addNotificationObserver
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveUserModelResponse:) name:@"sendUpdateRequestToServerForPhoneNumberWithUserModel" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveSMSVerificationResponse:) name:@"SMSVerificationForPhoneNumber" object:nil];
}
viewdiload
中,
viewdilead
中的
viewdilead
将出现
removeObserver
中的
dealloc

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"sendUpdateRequestToServerForPhoneNumberWithUserModel" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"SMSVerificationForPhoneNumber" object:nil];
}

但它根本没有表现出来。那么,如何更改我的
窗口层次结构呢视图控制器中的code>。如果您理解,请回复。非常感谢。

在主队列调度队列块中调用initializeAlertControllerForOneButtonWithTitle方法

所有UI操作都应在主威胁上。

 dispatch_async(dispatch_get_main_queue(), ^{
        [self initializeAlertControllerForOneButtonWithTitle:@"Already Registered!" withMessage:kAlreadyRegisteredPhoneNumberMSGForChangePhoneNumber withYesButtonTitle:@"Ok" withYesButtonAction:nil];
 });