I am creating such a protocol.
@protocol parsingComplete <NSObject>
@optional
-(void) updateUI:(NSMutableDictionary*)foodList;
@end
@interface foodParser:NSObject<NSXMLParserDelegate>
@property(nonatomic, weak) id<parsingComplete> delegate;
@end
After the parsing is complete, I want this delegate to start. so I am doing something like this.
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
if (delegate)
{
[delegate updateUI:food];
}
}
Here is the delegate value nil. Anyone understands the source of this problem.
And I call my delegate as follows. here .h file {
@interface NHMainViewController : UIViewController<parsingComplete>
@property(nonatomic, strong)ATAFoodParser *foodParser;
@end
}
here .m file
{
@implementation NHMainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.foodParser = [[ATAFoodParser alloc] init];
self.foodParser.delegate = self;
}
-(void) updateUI:(NSMutableDictionary*)foodList{
NSLog(@"Dictionary:---->%@", foodList);
}
@end
}
updateUI is my delegation method that needs to be called. I do not call here. I went to my first class, where I created my protocol, I typed a delegate .. it's zero.
source
share