委托方法未在Tableview中调用

时间:2014-10-27 09:20:36

标签: ios objective-c uitableview uipopovercontroller

iPadApp:我有两个班TimeTableViewControllerMLCViewControllerMLCViewController中创建了一个协议,我希望在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");

}

3 个答案:

答案 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;