Custom delegate is returning nil value

Viewed 4778

I am creating a protocol like this.

   @protocol parsingComplete <NSObject>
   @optional
     -(void) updateUI:(NSMutableDictionary*)foodList;
   @end

   @interface foodParser:NSObject<NSXMLParserDelegate>

   @property(nonatomic, weak) id<parsingComplete> delegate;
   @end

After parsing complete I want this delegate to trigger. so i am doing something like this.

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    if (delegate) 
    {
        [delegate updateUI:food];
    }
 }

Here the delegate value is nil. Anyone understand the source of this problem.

And i am invoking my delegate like this. here is .h file {

 @interface NHMainViewController : UIViewController<parsingComplete>

 @property(nonatomic, strong)ATAFoodParser *foodParser;
 @end

}

here is .m file

{

@implementation NHMainViewController

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
       // Custom initialization
      }
      return self;
}

- (void)viewDidLoad
{
     [super viewDidLoad];
     self.foodParser = [[ATAFoodParser alloc] init];
     self.foodParser.delegate = self;
// Do any additional setup after loading the view.
 }


-(void) updateUI:(NSMutableDictionary*)foodList{
       NSLog(@"Dictionary:---->%@", foodList);
 }

@end

}

updateUI is a my delegate method, which should get invoked. i am not getting call back here. i went to my first class where i have created my protocol, i printed delegate.. it is nil..

2 Answers
Related