I’m completely stuck with calling a method from a UIView subclass, the method just doesn’t get fired, I have a feeling that I’m doing something wrong but after searching the web I did not find any clue. Thank you in advance
Here’s the iPadMainViewController.h file
#import <UIKit/UIKit.h>
#import "TouchView.h"
@interface iPadMainViewController : UIViewController <TouchViewDelegate>
@property (retain) UIWebView *detailsView;
@end
and the iPadMainViewController.h file that holds the method
- (void)MethodNameToCallBack:(NSString *)s
{
NSLog(@"%@",s);
}
Here’s the TouchView.h file, which is supposed t
@protocol TouchViewDelegate
- (void)MethodNameToCallBack:(NSString *)s;
@end
@interface TouchView : UIView {
id<TouchViewDelegate> delegate;
}
@property (nonatomic, assign) id delegate;
@end
Here’s the TouchView.m file which is supposed to call a method of it’s delegate
@implementation TouchView
@synthesize delegate;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"HELLO FROM INSIDE");
[[self delegate] MethodNameToCallBack:(NSString *)@"HELLO FROM OUTSIDE"];
}
@end
Synthesizing the delegate is not enough, because it just creates the getter and the setter methods. It does not create an instance of
iPadMainViewController.So after you create an instance of
TouchView, you should assign an instance ofiPadMainViewControlleras the delegate.Or in the iPadMainViewController’s viewDidLoad method: