簡體   English   中英

委托方法未在Tableview中調用

[英]Delegate method is not calling in the Tableview

iPadApp:我有兩個班TimeTableViewControllerMLCViewController創造了一個協議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");

}

試穿

self. before fifthViewController.Mlcdelegate = self;

嘗試這個,

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
MLCViewController* vc = (MLCViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MLCNote"];
vc.Mlcdelegate = self;
self.fifthViewController = vc;

//rest stuff

添加此代碼

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM