2010-08-20 39 views
0

長時間潛伏者,第一次海報。代表職能不被稱爲

我正在製作一個ServerConnection模塊,使它成爲一個模塊化且更容易的模塊,但無法使代理調用。我已經看到了更多這樣的問題,但沒有一個答案解決了我的問題。

ServerConnection設置爲協議。因此,在Login.m中創建一個ServerConnection對象,該對象調用服務器,然後在Login中添加委託方法來處理是否有錯誤或者是否完成,這些由ServerConnection調用,如下所示。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 

    if([self.delegate respondsToSelector:@selector(connectionDidFinish:)]) { 
     NSLog(@"DOES RESPOND"); 
     [self.delegate connectionDidFinish:self]; 
    } else { 
     NSLog(@"DOES NOT RESPOND"); 
    } 

    self.connection = nil; 
    self.receivedData = nil; 

} 

它總是「不響應」。我已經嘗試了CFRunLoop技巧(下面),但它仍然不起作用。

- (IBAction)processLogin:(id)sender { 

    // Hide the keyboard 
    [sender resignFirstResponder]; 

    // Start new thread 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

    // Acutally call the server 
    [self authenticate]; 

    // Prevent the thread from exploding before we've got the data 
    CFRunLoopRun(); 

    // End thread 
    [pool release]; 

} 

我複製了Apple URLCache demo相當嚴重,並比較他們倆很多次,但無法找到任何差異。

任何幫助將不勝感激。

回答

2

這裏有問題要問:

  • 貴委託connectionDidFinishLoading:應對?
  • 簽名是否匹配,即它需要另一個對象?
  • 是否設置了代表或者是否爲零? (用這種方法檢查這個)

如果其中任何一個是「否」,你會看到「沒有迴應」......並且所有可能發生在你的應用程序中,但都很容易弄清楚。

+0

非常感謝。它缺少的 'self.delegate = theDelegate;' 在此函數 ' - (ID)initWithURL:(的NSString *)theURL withData:(的NSString *)海圖代表:(ID )theDelegate; {' – user426140 2010-08-22 00:08:26