开发者

@selector and return value

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


if ([self.delegate respondsToSelector:@selector(authRequired:)]) { 

In ObjC, the colons (:) in the method name is significant. That means authRequired and authRequired: are different methods. Try this instead:

if ([delegate respondsToSelector:@selector(authRequired)]) {
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜