开发者

ModalViewController delegate confusion

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:

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14

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:

-[DataSyncV开发者_开发技巧iewController 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'


Your main view controller IS the delegate and should implement the protocol. Your modalView has a delegate that it calls when it is being dismissed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜