开发者

Delegate functions not being called

Long time lurker, first time poster.

I'm making a ServerConnection module to make it a whole lot modular and easier but am having trouble getting the delegate called. I've seen a few more questions like this but none of the answers fixed my problem.

ServerConnection is set up as a protocol. So a ServerConnection object is created in Login.m which makes the call to the server and then add delegate methods in Login to handle if there's an error or if it's done, these are called by ServerConnection like below.

- (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; 

}

It always "does not respond". I've tried the CFRunLoop trick (below) but it still doesn't work.

- (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];

}

I copied the Apple URLCache demo pretty heavily and have compared them both many times but can't find any discrepancies.

Any help would b开发者_如何学Ce greatly appreciated.


Here are the questions to ask:

  • Does your delegate respond to connectionDidFinishLoading:?
  • Does the signature match, i.e. it takes another object?
  • Is the delegate set at all or is it nil? (Check this in that very method)

If any of those are "NO", you will see "doesn't respond"... and all equally likely to happen in your application, but all are easy to figure out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜