我的解析器使用 MWFeedParserDelegate delagate 调用 doneParsingObjects 非常好
@interface Parser ()<MWFeedParserDelegate>
...
-(void) doneParsingObjects{
NSLog(@"test");
}
现在,如果在不同的类中,我分配解析器,我的委托方法 doneParsingObjects 永远不会被调用。
Parser * newsParser = [[Parser alloc]init];
我知道我可以将委托添加到不同的类,但想知道为什么当我启动解析器对象并实现委托时,委托方法不会被触发。
/* my View Controller */
@implementation getSourceAndTopicViewController
- (void)viewDidLoad
{
[super viewDidLoad];
Parser * newsParser = [[Parser alloc]init];
newsParser.dataSource = self;
NSURL * feedURL = [NSURL URLWithString:@"http://news.yahoo.com/rss/"];
[newsParser parseURL:feedURL];
}
/* this method never gets called. Don't know why */
-(void) Parser:(parserViewController *)parser doneParsingObjects:(NSMutableArray *)parsedItems{
NSLog(@"Method was called");
}
_______________________________________
/* Parser.h Class */
@class Parser;
@protocol ParserDataSource
-(void) Parser:(Parser *)parser doneParsingObjects:(NSMutableArray *)parsedItems;
@end
@interface Parser : NSObject
@property (nonatomic, weak)id <ParserDataSource > dataSource;
/* Parser.m
I'd like to call my own datasource method in the viewController once MWFeedParser calls back feedParserDidFinish */
@interface Parser ()<MWFeedParserDelegate>{
MWFeedParser *feedParser;
}
...
@end
@implementation Parser
...
/* This method is supposed to be called by the MWFeedParserDelegate but never gets triggered from my view controller when I instantiate newParser */
- (void)feedParserDidFinish:(MWFeedParser *)parser {
NSLog(@"%@", self.MWFeedItems);
[self.dataSource Parser:self doneParsingObjects:self.parsedItems;
}
我知道如果我在我的视图控制器中使用 MWFeedParserDelegate,这个问题就会得到解决,但我想让解析器成为处理 MWFeedParserDelegate 的那个。