转 UIAlertView 不显示、屏幕变灰

UIAlertView 不显示、屏幕变灰
SvenFang
1181
在

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(response:) name:url object:nil];

的回调方法response里面弹出UIAlertView,当执行到该代码时,屏幕变灰,但是UIAlertView没有出现,背景按钮均不可点击,输出得到UIAlertView对象的centre x和y均为0 ,alpha为1,等高人指点,下面是response方法的代码和屏幕截图

- (void)response:(NSNotification *)notification
{
    if (isStop == 0) {//数据超时后,不作处理
        return;
    }
    if (isStop == 1) {
        [_timer invalidate];
        isStop = 0;
    }
    //停止等待控件
    [spinner performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:NO];
    [spinner removeFromSuperview];
    CommentXMLParser *commentXML=[notification object];
//    if([commentXML.responseDict objectForKey:@"return_result"]!=nil){
//        
//        NSLog(@"请求4001的返回---%@",[commentXML.responseDict objectForKey:@"return_result"]);
//        
//        if([[commentXML.responseDict objectForKey:@"return_result"] isEqualToString:RETURN_NO])
//        {
//            //这里只指网络失败
//            cmd = commentXML.returnHeader.cmd;
//            [self performSelectorOnMainThread:@selector(showDisconeect) withObject:nil waitUntilDone:NO];
//        }
//    }
    if(commentXML.done){ //如果有数据返回
        if([commentXML.returnHeader.rspcode isEqualToString:RESPONSE_SUCCESS])
        {//正确返回
            
            //解析协议
            if( [commentXML.returnHeader.cmd isEqualToString:B2B00004001])
            {
                score = [commentXML.responseDict objectForKey:@"integral_all"];
                score_can_use = [commentXML.responseDict objectForKey:@"integral_able"];
                balance = [commentXML.responseDict objectForKey:@"balance"];
                
                [self performSelectorOnMainThread:@selector(viewUpdateBaseInfo) withObject:nil waitUntilDone:NO];
            }
            else if([commentXML.returnHeader.cmd isEqualToString:B2B00004017])
            {
                gift_card_balance = [commentXML.responseDict objectForKey:@"balance"];
                [self performSelectorOnMainThread:@selector(viewUpdateBaseInfo) withObject:nil waitUntilDone:NO];
            }
            else if([commentXML.returnHeader.cmd isEqualToString:B2B00004002])
            {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"Settlement" object:commentXML.responseDict];
                [self performSelectorOnMainThread:@selector(closePayTool) withObject:nil waitUntilDone:NO];
            }
            else{
                NSAssert(true, @"非法协议,本处理函数只处理4001,4017, 4002协议", nil);
            }
        }else{//如果业务失败
            NSLog([commentXML.returnHeader.cmd stringByAppendingString:@"业务失败, 失败原因:%@"], [commentXML.headerDict objectForKey:@"rspdesc"]);
            
            //todo 提示业务失败, 类似android的toast效果
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[commentXML.headerDict objectForKey:@"rspdesc"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alert show];
            [alert release];
//            [OMGToast showWithText:[commentXML.headerDict objectForKey:@"rspdesc"] bottomOffset:10 duration:5];
        }
    }



评论 (1) • 分享 • 链接 • 2012-09-11 
0
Alert的delegate设置了吗? – 吴复 2012-09-11
1个答案 票 数  
davidzhang
01
在这里面我建议你这样做,将下面这段代码

//todo 提示业务失败, 类似android的toast效果
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[commentXML.headerDict objectForKey:@"rspdesc"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alert show];

改为

[alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];

如果还是不明白,可以参考这里http://www.gowhich.com/blog/206

转:http://www.dewen.org/q/5474

你可能感兴趣的:(uialertview)