2

我有以下代码...

-(void) SetSerialNumber
{
    NSLog(@"SetSerialNumber");
    NSString *serialNum = textFieldSecond.text;
    if (textFieldSecond.text == nil) {
        [self performSelectorOnMainThread:@selector(display:) withObject:@"Please Enter the serial number" waitUntilDone:YES];
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^(void){
        NSString* response;
        [self performSelectorOnMainThread:@selector(display:) withObject:@"Sending Set  Serial Num request" waitUntilDone:YES];
        [[testApp sharedClass] SetSerNumber:serialNum];

        [self performSelectorOnMainThread:@selector(display:) withObject:@"Waiting for Response..." waitUntilDone:YES];
        response = [[Process sharedProcess] readAndProcessData:ACK];
        [self performSelectorOnMainThread:@selector(display:) withObject:rpcresponse waitUntilDone:YES];
    });
}

该方法display:将消息放在UITextView.

我在按下按钮时调用此函数。有时 dispatch_async 块没有被调用。它只是通过它。但是,我每次都可以看到打印的日志消息。

任何人都可以分享可能导致这种情况的原因吗?

4

1 回答 1

2

你说的“跌倒”是什么意思?该调用是异步的,因此不会在那里发生。将日志添加到块本身并查看它是否被打印。

您确定当它“失败”时,serialNum 不为零吗?

于 2013-11-14T19:27:10.447 回答