iPadApp:我有两个班TimeTableViewController
和MLCViewController
在MLCViewController
中创建了一个协议,我希望在TimeTableViewController
中调用该协议。但delegate(protocol)
方法并未调用TimeTableViewController
。
这是我的代码......。
在 MLCViewController.h
中//created protocol
@protocol MLCCancelDelegate;
@protocol MLCCancelDelegate <NSObject>
@optional
-(void)CancelMLCSession;
@end
@property(nonatomic,weak)id <MLCCancelDelegate>Mlcdelegate;
MLCViewController.m
//Which is written in a UIAlertView Delegate method
switch (buttonIndex) {
case 0:
{
if (self.Mlcdelegate && [self.Mlcdelegate respondsToSelector:@selector(CancelMLCSession)])
{
[self.Mlcdelegate CancelMLCSession];
}
break;
}
default:
break;
}
}
在 TimeTableViewController.m
中//ViewDidLoad
self.fifthViewController=[[MLCViewController alloc]init];
fifthViewController.Mlcdelegate = self;
//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:@"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:vc];
pc.delegate = self;
[pc presentPopoverFromRect:rect inView:collectionData
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//Iam calling that delegate method like
-(void)CancelMLCSession{
NSLog(@"cancelling");
}
答案 0 :(得分:0)
尝试放
self. before fifthViewController.Mlcdelegate = self;
答案 1 :(得分:0)
试试这个,
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MLCViewController* vc = (MLCViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MLCNote"];
vc.Mlcdelegate = self;
self.fifthViewController = vc;
//rest stuff
答案 2 :(得分:0)
添加此代码
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self.fifthViewController = [storyboard instantiateViewControllerWithIdentifier:@"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:self.fifthViewController];
pc.delegate = self;
self.fifthViewController.Mlcdelegate=self;