委托方法未调用

时间:2014-11-21 13:54:50

标签: ios objective-c delegates xcode6

我不确定为什么我的委托方法没有被调用。下面是我的代码。请告诉我我在哪里弄错了。 我已经正确设置了所有设置,我确信我犯了一个愚蠢的错误。我委托的方法没有被调用。任何帮助将不胜感激

LSFiveViewController.h

    @protocol OneToOne;
    @protocol OneToOne <NSObject>
    @optional
    -(void)dismissPopOverlsfive;
    @end

    #import <UIKit/UIKit.h>
    #import "AppDelegate.h"
    #import "TimeTableViewController.h"


    @class TimeTableViewController;

    @interface LearningSessionFiveDetailsViewController : UIViewController<UITextFieldDelegate>
    {
        NSString *bookingString;
    }

    @property(nonatomic,weak)id<OneToOne>OneToOne;

    @end


**LSFiveViewController.m**


    @synthesize sessionAndDateLabelObj,OneToOne

    - (void)viewDidLoad
    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.
    }


    - (IBAction)BookSingleSessionAction:(id)sender
    {


    if (self.OneToOne && [self.OneToOne respondsToSelector:@selector(dismissPopOverlsfive)])
        {
            [self.OneToOne dismissPopOverlsfive];
        }

    }

    @end

TimeTableViewController.h

#import "OneToOneViewController.h"
#import "LearningSessionFiveDetailsViewController.h"
//other codes

@property(nonatomic,strong)LearningSessionFiveDetailsViewController *LSFiveObj;

@end

TimeTableViewController.m

#import "TimeTableViewController.h"

#import "LearningSessionFiveViewController.h"
#import "UIAlertView+Blocks.h"

- (void)viewDidLoad
{
 LSFiveObj=[[LearningSessionFiveDetailsViewController alloc]init];
    self.learnSearchFiveClassObj.OneToOne=self;
}

-(void)dismissPopOverlsfive
{
   This method is not being called

}

2 个答案:

答案 0 :(得分:1)

请放这个

self.LSFiveObj.OneToOne=self;

而不是

self.learnSearchFiveClassObj.OneToOne=self;

并在您的课程中添加OneToOne协议

答案 1 :(得分:1)

这一行:

self.learnSearchFiveClassObj.OneToOne=self;

应该是

self.LSFiveObj.OneToOne=self;

一般而言,属性名称不应以大写字母开头,仅适用于类。