2014-11-21 132 views
0

我不知道爲什麼我的委託方法沒有被調用。下面是我的代碼。請告訴我我犯了什麼錯誤。 我已經完成了所有的設置,我相信我犯了一個愚蠢的錯誤。我的委託方法沒有被調用。任何幫助將不勝感激委託方法不叫

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 

} 
+0

您是否在任何地方使用'setDelegate:'? – 2014-11-21 13:56:06

+0

self.learnSearchFiveClassObj.OneToOne = self; 這部分代碼將作爲「集合委託」工作 – iOSDeveloper 2014-11-21 13:58:50

+0

嘗試將「< OneToOne >」添加到「TimeTableViewController」。嘗試檢查「如果」中的哪一項測試爲否。 – Larme 2014-11-21 14:05:59

回答

1

請將代替

self.learnSearchFiveClassObj.OneToOne=self; 

self.LSFiveObj.OneToOne=self; 

,並在你的類添加OneToOne協議

+0

我添加了所有這些...不工作 – iOSDeveloper 2014-11-21 14:48:54

+0

你能告訴我你在使用Storyboard還是Xib? 如果Storyboard那麼你正在初始化viewcontroller實例是錯誤的。 使用此 LSFiveObj = [self.storyboard instantiateViewControllerWithIdentifier:@「storyboard id」]; – 2014-11-23 06:48:31

1

這裏這條線:

self.learnSearchFiveClassObj.OneToOne=self; 

應該

self.LSFiveObj.OneToOne=self; 

一般而言,屬性名稱不應以大寫字母開頭,僅適用於類。

+0

是的,我知道它只是一個拼寫錯誤 – iOSDeveloper 2014-11-22 06:36:52