Hi all,
I'm just trying to build a simple delegate, it compiles successfully but it doesn't seem to do anything right now. Please review my code below, both FirstViewContoller and SecondViewController have separate xib files, the SecondViewController has a button hooked up to the myMethod of course.
I've been learning my way around objective c and iPhone SDK for a couple of months, I've been using a book and lynda.com tutorial to aid, I actually copied most of the code using the xcode template for a utility app, and I believe I understand what is going on here, but is there something I've missed, as the button isn't responding.
If you need more info please ask.
Many thanks, Chris
SecondViewController.h
#import <UIKit/UIKit.h>
@protocol SecondViewControllerDelegate;
@interface SecondViewController : UIViewController {
id <SecondViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <SecondViewControllerDelegate> delegate;
-(IBAction) myMethod;
@end
@protocol SecondViewControllerDelegate
-(void)viewControllerDidFinish:(SecondViewController *)controller;
@end
SecondViewController.m
@implementation SecondViewController
@synthesize delegate;
-(IBAction) myMethod
{
[self.delegate viewControllerDidFinish:self];
}
//
@end
FirstViewController.h
@interface FirstViewController : UIViewController <SecondViewControllerDelegate>{
//
@end
FirstViewController.m
@implementation FirstViewController
-(void)viewControllerDidFinish:(SecondViewControllerDelegate *)controller
{
NSLog(@"delegate is being used");
}
//
@end