@selector and return value

Posted by user320926 on Stack Overflow See other posts from Stack Overflow or by user320926
Published on 2010-04-21T05:43:57Z Indexed on 2010/04/21 5:53 UTC
Read the original article Hit count: 242

Filed under:
|

The idea it's very easy, i have an http download class, this class must support the http authentication but it's basically a background thread so i would like to avoid to prompt directly to the screen, i would like to use a delegate method to require from outside of the class, like a viewController.

But i don't know if is possible or if i have to use a different syntax.

This class use this delegate protocol:

//Updater.h
@protocol Updater <NSObject>
-(NSDictionary *)authRequired;
@optional
-(void)statusUpdate:(NSString *)newStatus;
-(void)downloadProgress:(int)percentage;
@end



@interface Updater : NSThread {
...
}

This is the call to the delegate method:

//Updater.m
// This check always fails :(
if ([self.delegate respondsToSelector:@selector(authRequired:)]) { 
    auth = [delegate authRequired];
}

This is the implementation of the delegate method

//rootViewController.m
-(NSDictionary *)authRequired;
{
    // TODO: some kind of popup or modal view
    NSMutableDictionary *ret=[[NSMutableDictionary alloc] init]; 
    [ret setObject:@"utente" forKey:@"user"];
    [ret setObject:@"password" forKey:@"pass"];
    return ret;
}

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about objective-c