Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何区分 关闭类型 #157

Open
1996GJ opened this issue Oct 9, 2021 · 6 comments
Open

如何区分 关闭类型 #157

1996GJ opened this issue Oct 9, 2021 · 6 comments

Comments

@1996GJ
Copy link

1996GJ commented Oct 9, 2021

.LeeAddAction(^(LEEAction *action) {
action.clickBlock = ^{

    };
})    

.LeeCloseComplete(^{
// 关闭回调事件

 })

现在有这个问题,如果添加了下面的关闭回调事件,就不能触发 按钮的回调方法了,这样我就区分不了是点击背景关闭,还是点击按钮事件

@lixiang1994
Copy link
Owner

??? 按钮的回调不会不触发的呀

@1996GJ
Copy link
Author

1996GJ commented Oct 9, 2021

按钮的回调就不触发了,每次回调的都是 LeeCloseComplete 这个了,我又封装了一层
.LeeAddAction(^(LEEAction *action) {

    action.clickBlock = ^{
        if (completion) {
                completion(1);
        }
    };
})

.LeeCloseComplete(^{
// 关闭回调事件
if (completion) {
completion(2);
}
})
这样每次拿到的都是2 不管点击的按钮还是背景

@lixiang1994
Copy link
Owner

这是来自Demo的代码, 你可以试试 打印是正常的... 值得注意的是 LeeCloseComplete回调会先于action的回调

[LEEAlert alert].config
            .LeeTitle(@"这是一个alert 它有三个不同类型的action!")
            .LeeAction(@"一个默认action", ^{
                
                // 点击事件Block
                NSLog(@"000");
            })
            .LeeDestructiveAction(@"一个销毁action", ^{
                
                // 点击事件Block
                NSLog(@"222");
            })
            .LeeCancelAction(@"一个取消action", ^{
                
                // 点击事件Block
                NSLog(@"111");
            })
            .LeeCloseComplete(^{
                NSLog(@"333");
            })
            .LeeShow();

@1996GJ
Copy link
Author

1996GJ commented Oct 9, 2021

是的 问题就在于此,我想要 区分出来,点击背景关闭和点击按钮处理不同的方法,但是现在点击按钮后,会触发两次回调

@lixiang1994
Copy link
Owner

我提供一个思路 方法内提供一个局部block变量, 这个block内调用completion(), 然后按钮回调和关闭回调调用这个block变量, 只要有一方调用了这个block变量 接下来就置空它, 另一个就调用不到了, 你可以将关闭回调的调用async一下 这样就变成了按钮回调优先.

@lixiang1994
Copy link
Owner

这样就可以区分是按 钮点击关闭 还是 其他原因关闭 了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants