0
这个想法很容易,我有一个http下载类,这个类必须支持http认证,但它基本上是一个后台线程,所以我想避免直接提示到屏幕,我想使用委托方法从类外部请求,如viewController。@选择器和返回值
但我不知道是否可能或者如果我必须使用不同的语法。
此类使用该委托方案:
//Updater.h
@protocol Updater <NSObject>
-(NSDictionary *)authRequired;
@optional
-(void)statusUpdate:(NSString *)newStatus;
-(void)downloadProgress:(int)percentage;
@end
@interface Updater : NSThread {
...
}
这是调用委托方法:
//Updater.m
// This check always fails :(
if ([self.delegate respondsToSelector:@selector(authRequired:)]) {
auth = [delegate authRequired];
}
这是委托方法
//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;
}
hehehe,nice,thx :) – Cesar 2010-04-21 10:45:03