2014-09-25 23 views
0

我剛接觸iOS編程,現在我編寫了一個必須連接到SOAP WS的應用程序。我使用互聯網(SudzC)的軟件來爲WS生成包絡類。要接收來自服務的響應,它使用@selector,它將執行傳遞給響應處理程序例程。儘管如此,當程序流進入響應的處理程序時,它會返回到初始例程(完成其工作後),但令我驚訝的是,我發現調用例程已完成,並且在那之後調用了處理程序例程。可能是我不明白iOS程序流程!@selector如何影響iOS中的程序流程?

有關涉及@selector的程序流程的下降說明嗎?

編輯: 下面是示例代碼:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    WS* service = [WS service]; 
    service.logging = YES; 

    [service WS_Method:self action:@selector(WS_MethodHandler:) iParam1: 1 sParam2: @"string" iParam3: 1]; 

    NSLog(@"!!! Finish !!!"); 
} 

- (void) WS_MethodHandler: (id) value { 

    // Handle errors 
    if([value isKindOfClass:[NSError class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    // Handle faults 
    if([value isKindOfClass:[SoapFault class]]) { 
     NSLog(@"%@", value); 
     return; 
    } 

    WS_CheckIussue* result = (WS_CheckIussue*)value; 
    NSLog(@"WS_CheckIussue returned the value: %@", result); 
NSLog(@"!!! Finish !!! 2"); 
} 

因此,我有!完成!在那之後 !!!完成! 2

+0

-1因爲你沒有發佈任何代碼。 – SevenBits 2014-09-25 13:08:24

+0

我沒有發佈任何代碼,因爲我認爲這是一些普遍的行爲。我編輯我的問題。 – new2ios 2014-09-25 13:11:31

+1

@SevenBits您不需要*在問題或答案中發佈代碼。 +1來補償。 – Droppy 2014-09-25 13:15:13

回答

0

網絡代碼通常在單獨的線程上運行。所以我會假設你的代碼看起來像這樣:

- (void)downloadData 
{ 
    //Step 1 : Request data from webservice 
    WebServiceDohickey * webservice = [[WebServiceDohickey alloc] init]; 
    //This will run on a separate thread. 
    //The selector passed in may be performed during or after any other code in this method 
    [webservice getWebServiceResponseWithCallback:@selector(responseHandler:) 
              target:self]; 

    //Step 3 : Invalid program flow area 
    //I'm guessing you have more code here that you expect to happen after the code in your responseHandler, but it actually executes before. That code should be in the responseHandler method 
} 
- (void)responseHandler:(WebServiceResponse *)response 
{ 
    //Step 2 : Handle response object 

    //Step 3 : This is where step 3 should live 

    //Side note : Your callback may need to specifically be put on a specific thread. 
    //Wrap step 2 and 3 in a block like this to put it on the main thread which is common for UI code execution. 
    dispatch_async(dispatch_get_main_queue(), ^{ 

    }); 
} 
+1

是的,我的問題是因爲我使用網絡代碼,它在單獨的線程中運行。 – new2ios 2014-09-26 11:48:53

相關問題