Kex
Kex

Reputation: 776

Delegate Action Never Gets Called

I'm having trouble using Protocols/Delegates when I was trying to reload the data from a UITableView in my rootViewController when my modal view is dismissed.

Here is some code from my modal view .h file:

@protocol LoginWebViewDelegate <NSObject>
     -(void) updateFromModalView;
@end

@interface myModalView : UIViewController{
    id<LoginWebViewDelegate> loginDelegate; 
    ..
}
@property (nonatomic, assign) id<LoginWebViewDelegate> loginDelegate;
..
-(IBAction)dismiss;
..

In my .m file I synthesize the loginDelegate & I implement the dismiss action & it's been activated when I press the button.

-(IBAction) dismiss
{
    NSLog(@"Button Pressed!");
    [loginDelegate updateFromModalView];
}

Next in the inteface of my rootViewController I added <LoginWebViewDelegate> & here is the action in my implementation:

-(void) updateFromModalView
{
    [modalView dismissModalViewControllerAnimated:YES];
    NSLog(@"Reloading Data");
    [dataController readPlist];
    [dataTable reloadData];
    [dataTable beginUpdates];
    [dataTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable endUpdates];
}

The method updateFromModalView never gets called. What do I miss?

Upvotes: 0

Views: 107

Answers (1)

jrturton
jrturton

Reputation: 119242

You are missing (or you haven't posted) the part where you assign a value to loginDelegate. You mention synthesising it but that only creates accessor methods, it doesn't set a value.

Somewhere in your code you need a statement like:

self.loginDelegate = _something_;

Or, whatever object creates this view controller would set itself or another object as the delegate after creating it but before presenting it:

modalController = [[ModalController alloc] initWithNibName:@"ModalController];
modalController.loginDelegate = self;
[self presentModalViewController:modalController];

Upvotes: 1

Related Questions