Reputation: 7
Quick question,
i have made a custom delegate
PupilView.h
@protocol DismissPupilViewPopoverDelegate
- (int) getPupilViewReason;
@end
@interface PupilView : UIViewController{
id<DismissPupilViewPopoverDelegate> delegate;
}
@property (nonatomic, assign) id<DismissPupilViewPopoverDelegate> delegate;
It is called in PupilView.m like follows
[[self delegate] getPupilViewReason];
in in my maincontroller.h
#import "PupilView.h"
@interface MainScreen : UIViewController<DismissPupilViewPopoverDelegate>
maincontroller.m
-(int) getPupilViewReason
{
return 100;
}
If i put the [[self delegate] getPupilViewReason]; in any function in pupilview.m it works perfectly, returns 100 i can see it with a breakpoint etc.
If i put it in viewdidload it dosn't load, returns 0, dosnt hit breakpoints etc. Any help as to why.
thanks
Upvotes: 0
Views: 881
Reputation: 949
make a custom init method for the view controller where you pass the delegate so you can set the delegate in the init method before viewdidload is called.
@interface
- initWithDelegate:(id)aDelegate nibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//...
@end
@implementation
- initWithDelegate:aDelegate nibName:nibNameOrNil bundle:nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
_delegate = aDelegate;
///rest of init implementation
}
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.delegate getPupilViewReason];
}
//...
@end
Upvotes: 1
Reputation: 655
Yes, you can call the delegate in viewDidLoad function.
Suppose your delegate(request owner) name is "delegate" then you can call like -
- (void)viewDidLoad
{
[super viewDidLoad];
[<OBJ>.delegate GetPupilViewReason];
}
OBJ - is the instance of a class, have assign the delegate.
Upvotes: 0
Reputation: 1189
Go ahead and call. If the delegate is set up properly then it should work. Do you mean when you're doing a segue UI transfer?
Upvotes: 0