Reputation: 345
Protocol method not being called. I am using pop over controller. i get a nil delegate and the method in Time table view controller not being called. Where am i going wrong. I am new to this protocol. below is my code.. i just posted only main code removing all the other useless code... i just want to navigate from TimeTable view controller to Root view controller on selection of a button from PopOverView controller
TimetableView Controller.h
#import <UIKit/UIKit.h>
#import "NotesandReminders.h"
#import "AppDelegate.h"
#import "PopOverViewController.h"
@class PopOverViewController;
@interface TimeTableViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate,TestProtocol>
@property(nonatomic,strong)PopOverViewController *testViewController;
Timetable view controller.m
@interface TimeTableViewController ()
@end
@implementation TimeTableViewController
@synthesize testViewController;
- (void)viewDidLoad
{
self.testViewController=[[PopOverViewController alloc]init];
testViewController.delegate=self;
}
-(void)LogOut
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
POPOVER VIEW CONTROLLER.H
@protocol TestProtocol <NSObject>
@required
-(void)LogOut;
@end
POP OVER VIEW CONTROLLER.H
#import <UIKit/UIKit.h>
#import "TimeTableViewController.h"
@class TimeTableViewController;
@interface PopOverViewController : UIViewController <UIPopoverControllerDelegate>
{
id<TestProtocol>delegate;
}
- (IBAction)out:(id)sender;
@property(nonatomic,strong)TimeTableViewController *testTimeTableViewController;
@property(nonatomic,strong)UIPopoverController *popoverController;
@property(retain) id<TestProtocol>delegate;
@end
POP OVER VIEW CONTROLLER.M
#import "PopOverViewController.h"
@interface PopOverViewController ()
@end
@implementation PopOverViewController
@synthesize delegate;
@synthesize popoverController,testTimeTableViewController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
self.delegate=testTimeTableViewController;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)out:(id)sender {
self.TimeObj=[[TimeTableViewController alloc]init];
[self.TimeObj Signout];
}
@end
Upvotes: 1
Views: 92
Reputation: 8218
I think the problem may be with the viewDidLoad
method, when you assign self.delegate=testTimeTableViewController;
, because testTimeTableViewController
was never initialized.
Since you are assigning the delegate when you create the view controller, you should not assign it again.
Also, you must not retain
the delegate, use a weak
reference instead.
Upvotes: 1