我有 2 个 UIViewControllers、GameController 和 RhythmController。我像这样在RhythmController.h中定义了 RhythmDelegate 。RhythmController 中的 doEndGame 方法应该调用 GameController gameOver 中的委托方法,它实现了委托协议。
我不明白为什么这不起作用......我的代码有错误吗?提前感谢您的帮助。
@class RhythmView,RhythmDelegate, RhythmController;
@protocol RhythmDelegate
@required
-(void)gameOver:(RhythmController*)aRhythmController;
@end
@interface RhythmController : UIViewController <UIGestureRecognizerDelegate, UIAlertViewDelegate> {
.....
}
@property (nonatomic, retain) IBOutlet NSObject<RhythmDelegate>* delegate;
在 RhythmController.m 中,我的委托调用如下:
@implementation RhythmController
@synthesize delegate;
-(void)doEndGame{
isPaused = true;
[delegate gameOver:self];
}
我确认 doEndGame 被调用,里面有一个断点。但是,它没有转到我在 GameController 中想要的方法,它实现了委托。
#import <UIKit/UIKit.h>
#import "CoinsController.h"
#import "CoinsGame.h"
#import "HighscoreController.h"
#import "RhythmController.h"
#import "RhythmView.h"
@interface GameController : UIViewController <RhythmDelegate> {
IBOutlet UIView *landscapePlayView;
IBOutlet UIView *landscapeGameHolderView;
IBOutlet UIView *portraitPlayView;
IBOutlet UIView *portraitGameHolderView;
IBOutlet UIView *loadingView;
IBOutlet UIView *welcomeView;
IBOutlet UIButton *continueButton;
IBOutlet UIView *aboutView;
IBOutlet UIView *playView;
IBOutlet UIView *rhythmView;
//IBOutlet UIView *levelSelectView;
IBOutlet UILabel *musicNotation;
IBOutlet CoinsController *coinsController;
IBOutlet RhythmController *rhythmController;
IBOutletCollection(UILabel) NSArray *remainingTurnsLabels;
IBOutletCollection(UILabel) NSArray *scoreLabels;
IBOutlet HighscoreController *highscoreController;
CoinsGame* previousGame;
BOOL isPlayingGame;
}
-(void)setPreviousGame:(CoinsGame*)aCoinsGame;
-(CoinsGame*)currentGame;
- (IBAction)continueGameClicked:(id)sender;
- (IBAction)newGameClicked:(id)sender;
- (IBAction)highScoresClicked:(id)sender;
- (IBAction)aboutClicked:(id)sender;
- (IBAction)aboutDoneClicked:(id)sender;
- (IBAction)highscoreDoneClicked:(id)sender;
-(void)loadImages;
-(void)showPlayView: (UIInterfaceOrientation)interfaceOrientation;
-(void)doPause;
@end
在 GameController.m 中,方法是
// RhythmDelegate Tasks
-(void)gameOver:(RhythmController*)aRhythmController{
NSLog(@"Came into gameOver delegated task");
[self.view addSubview: welcomeView];
}