ChrisXu / CXAlertView

Custom alert-view which allow you to add view as main content.
MIT License
323 stars 81 forks source link

main thread blocking #24

Open kaich opened 10 years ago

kaich commented 10 years ago

when i use it like this, CXAlertView * alert=[[CXAlertView alloc] initWithTitle:@"warning" message:message cancelButtonTitle:@"cancel"]; [alert addButtonWithTitle:@"continue" type:CXAlertViewButtonTypeDefault handler:^(CXAlertView alertView, CXAlertButtonItem button) { CXAlertView * secondeAlertView=[[CXAlertView alloc] initWithTitle:@"XX" message:@"xxxxxxxxxxxx" cancelButtonTitle:@"sure"]; [secondeAlertView show]; [alertView dismiss]; }];

when i click 'sure' button , the main thread is blocking. i can't touch my view any more! can you fix the bug ?

kaich commented 10 years ago

when i add a time delay, it works fine. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [alertView dismiss]; });

I am not find the real reason . but hope you fix the bug!

ChrisXu commented 10 years ago

Thanks, I will fix it ASAP.

jlubeck commented 10 years ago

Were you able to fix the bug?? I'm having a lot of problems with this... The dispatch_after method seemed to work, but now I'm getting double alertviews to show for a second before the first one disappears...

renanstig commented 9 years ago

@jlubeck I found a workaround for this bug.

I instantiated my alert view inside a dispatch_after method. See below:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    NSString *showmessage = [[NSString alloc] init];
    showmessage = [_defaults objectForKey:@"activatedFenceMessage"];
    if (![showmessage isEqualToString:@"1"]) {

        UIView *customAlertView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 260, 199)];

        UIImageView *ivFunc = [[UIImageView alloc] initWithFrame:CGRectMake(57, 8, 146, 88)];
        [ivFunc setImage:[UIImage imageNamed:@"apresentacao_cerca_criada"]];
        [ivFunc setContentMode:UIViewContentModeScaleAspectFit];
        [customAlertView addSubview:ivFunc];
        UILabel *mensagem = [[UILabel alloc] initWithFrame:CGRectMake(8, 108, 250, 53)];
        [mensagem setFont:[UIFont systemFontOfSize:11]];
        [mensagem setLineBreakMode:NSLineBreakByWordWrapping];
        [mensagem setNumberOfLines:6];
        [mensagem setTextAlignment:NSTextAlignmentCenter];

        mensagem.text = activatedFence;
        [customAlertView addSubview:mensagem];

        CXAlertView *alertViewMe = [[CXAlertView alloc] initWithTitle:fenceTitle contentView:customAlertView  cancelButtonTitle:nil];

        // This is a demo for multiple line of title.
        [alertViewMe addButtonWithTitle:multiLineMessageAcceptedText
                                   type:CXAlertViewButtonTypeDefault
                                handler:^(CXAlertView *alertView2, CXAlertButtonItem *button) {
                                    [_defaults setObject:@"0" forKey:@"activatedFenceMessage"];

                                    [alertView2 dismiss];

                                }];

        [alertViewMe addButtonWithTitle:multiLineMessageCancelText
                                   type:CXAlertViewButtonTypeCancel
                                handler:^(CXAlertView *alertView2, CXAlertButtonItem *button) {
                                    [_defaults setObject:@"1" forKey:@"activatedFenceMessage"];

                                    [alertView2 dismiss];

                                }];

        [alertViewMe show];
    }
});