I need to present a modal view controller and be notified when it is dismissed or notified that I need to dismiss it, looking here I am still confused:
I have my mainViewController and myModalView controller and I have the following code that needs to be implemented but not sure where - first up delegate protocal:
@protocol DataSyncDelegate <NSObject>
-(void) doneWithSync;
@end
which controller.h does this go in? I am assuming my modalViewController.h
second is my implementation:
-(void) doneWithSync {
[self dismissModalViewControllerAnimated:YES];
}
which controller.m does this go in? I am assuming my mainViewController.m
I also have the delegate properties that needs to be aded:
id delegate;
@property (nonatomic, retain) id delegate;
which controller.m does this need to go in? I am assuming my modalViewController.h
and here is how I am presenting the modalViewController from my MainViewController:
DataSyncViewController *dataSyncViewController = [[DataSyncViewController alloc] initWithOptions:FALSE];
dataSyncViewController.delegate = self;
[self presentModalViewController:dataSyncViewController animated:NO];
[dataSyncViewController release];
As of right now this gives me the following error:
-[DataSyncViewController setDelegate:]: unrecognized selector sent to instance 0x5952e20
What am I missing here?
EDIT - HERE IS MY MODAL VIEW CONTROLLER .H
#import <UIKit/UIKit.h>
@protocol DataSyncDelegate
-(void) doneWithSync;
@end
@interface DataSyncViewController : UIViewController {
id <DataSyncDelegate> delegate;
}
@property (nonatomic, retain) id <DataSyncDelegate> delegate;
@end
EDIT - MAIN VIEW CONTROLLER .H AND .M
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "DataSyncViewController.h"
@interface LoginViewController : UIViewController <DataSyncDelegate>{
}
@end
HERE IS THE CREATION OF THE MODAL:
DataSyncViewController *dataSyncViewController = [[DataSyncViewController alloc] initWithOptions:FALSE];
dataSyncViewController.delegate = self;
[self presentModalViewController:dataSyncViewController animated:NO];
[dataSyncViewController release];
HERE IS MY IMPLEMENTATION OF THE DELEGATE:
-(void) doneWithSync {
[self dismissModalViewControllerAnimated:YES];
}
And now everything looks to wire up correctly in the compiler but I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[DataSyncViewController setDelegate:]: unrecognized selector sent to instance 0x59e4b40'