1
我在努力解決對我提出的回調函數這個問題。 下面是我定義我的全球塊:不相容的嵌段指針類型發送「無效(^)(布爾)」到類型的參數「無效(^)()」
#import <Foundation/Foundation.h>
#import "cocos2d.h"
typedef void (^RestartBlock)(bool);
RestartBlock block = ^(bool restart)
{
if (restart) {
// restart
}
else
{
// continue
}
};
@interface RestartDialogLayer : CCLayer
{
RestartBlock m_block;
bool m_bRestart;
}
-(id) initWithBlock:(RestartBlock)block;
-(void) restartButtonPressed:(id)sender;
-(void) resumeButtonPressed:(id)sender;
@end
RestartDialogLayer的執行情況:
#import "RestartDialogLayer.h"
@implementation RestartDialogLayer
-(id) initWithBlock:(RestartBlock)block
{
if ((self = [super init]))
{
m_bRestart = YES;
m_block = block;
}
return self;
}
-(void) restartButtonPressed:(id)sender
{
m_bRestart = YES;
m_block(m_bRestart);
[self removeFromParentAndCleanup:YES];
}
-(void) resumeButtonPressed:(id)sender
{
m_bRestart = NO;
m_block(m_bRestart);
[self removeFromParentAndCleanup:YES];
}
-(void) dealloc
{
[super dealloc];
}
@end
我用的是塊另一個類的這樣的方法:
-(void) singlePlayerSceneSchedule:(ccTime) delta
{
CCLOG(@"demoSceneSchedule MainMenuScene");
[self unschedule:_cmd];
bool gameLeftActive = [Globals sharedGlobals].gameLeftActive;
if (gameLeftActive)
{
RestartDialogLayer* dialog = [[RestartDialogLayer node] initWithBlock:block];
}
else
{
// Start a new game
}
}
任何幫助表示讚賞。
感謝,
如何界定這種方法'? - (ID)initWithBlock:????(RestartBlock)塊{}'它'(RestartBlock)block'作爲輸入參數可以請你發佈此問題的截圖 – iDev
你檢查'm_block'具有正確的類型 – Matthias
是,RestartBlock m_block; –