1

我的应用程序中有一个UIAlertController,所以我希望每次menuButton按下时都显示警报。我需要重新创建_menuAlert特定的想法(它需要检查另一个对象action,没有描述)。因此,如果我保留_shareAction,但重新创建UIAlertController,不知何故,它的处理程序变为nil.

我觉得错过了一些关于块的重要内容,以了解为什么会发生这种情况。请帮我理解。

有代码:

- (UIAlertController *)menuAlert
{
    _menuAlert = [UIAlertController alertControllerWithTitle:nil
                                                     message:nil
                                              preferredStyle:UIAlertControllerStyleActionSheet];

    @weakify(self);
    if (!_shareAction)
    {
        _shareAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"SHARE_BTN_TEXT", nil)
                                                style:UIAlertActionStyleDefault
                                              handler:^(UIAlertAction * _Nonnull action) {
                                                  @strongify(self);
                                                  [self.navigationController presentShareVCWithList:_list];
                                              }];
    }

    if (!_cancelAction) {
        _cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"ALERT_CANCEL", nil)
                                                 style:UIAlertActionStyleCancel
                                               handler:nil];
    }


    [_menuAlert addAction:_shareAction];
    [_menuAlert addAction:_cancelAction];

    return _menuAlert;
}

menuAlert 如何调用:

- (void)menuButtonPressed 
{
    [self presentViewController:self.menuAlert animated:YES completion:nil];
    self.menuAlert.view.tintColor = COLOR_BACKGROUND_GREEN;
}
4

0 回答 0