lixiang1994 / LEEAlert

优雅的可自定义 Alert ActionSheet
MIT License
1.29k stars 203 forks source link

尝试封装的时候出现无法弹窗的问题 #164

Closed Sadow32 closed 2 years ago

Sadow32 commented 2 years ago

写了一个类方法,方法里的代码如下。

// 这里获取了一下config的对象
LEEBaseConfigModel *config = [LEEAlert alert].config;
    config.LeeAddTitle(^(UILabel * _Nonnull label) {
        label.text = @"123123";
        label.textColor = UIColor.titleDarkColor;
        label.font = [UIFont systemFontOfSize:15];
    }).LeeAddContent(^(UILabel * _Nonnull label) {
        label.text = @"123123";
        label.font = [UIFont systemFontOfSize:15];
        label.textColor = UIColor.titleColor;
    }).LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"123123";
    }).LeeAddAction(^(LEEAction * _Nonnull action) {
        action.title = @"123123";
    }).LeeShow();

如果正常按照示例写就不会出现问题,这是正常现象吗,可以这么使用吗?

lixiang1994 commented 2 years ago

[LEEAlert alert] 这个再拆一个

Sadow32 commented 2 years ago

改了一下,这样确实正常了。

/// LeeAlert
/// @param title 标题
/// @param content 内容
/// @param actions 按钮数组
/// @param block 回调
+ (void)alertTitle:(nullable NSString *)title
           content:(nullable NSString *)content
           actions:(nonnull NSArray *)actions
             block:(alertActionBlock)block {

    LEEAlertConfig *alert = [LEEAlert alert];
    alert.config.LeeAddTitle(^(UILabel * _Nonnull label) {
        label.text = title;
        label.textColor = UIColor.titleDarkColor;
        label.font = [UIFont systemFontOfSize:15];
    }).LeeAddContent(^(UILabel * _Nonnull label) {
        label.text = content;
        label.font = [UIFont systemFontOfSize:15];
        label.textColor = UIColor.titleColor;
    });
    for (NSInteger i = 0; i < actions.count; i++) {
        AlertActionModel *model = [actions objectAtIndex:i];
        alert.config.LeeAddAction(^(LEEAction * _Nonnull action) {
            action.title = model.title;
            action.titleColor = model.color;
            action.font = [UIFont systemFontOfSize:model.fontSize];
            action.clickBlock = ^{
                if (block) {
                    block(i, model.title);
                }
            };
        });
    }
    alert.config.LeeShow();
}
lixiang1994 commented 2 years ago

good!