为什么我的代码块实例变量没有初始化并打印出 "NSGlobalBlock"?

Why is my Code Block Instance Variable not Initializing and printing out a "NSGlobalBlock"?

我正在使用 sprite 生成器和 Xcode。

有人看到我的代码块哪里出错了吗"whereToNext" 属性?我试图用它在场景之间导航,但由于某种原因,它没有进入 -(void)patterns 中的初始化代码,即使它进入了 patterns 方法。因为它永远不会进入 whereToNext=^{} 代码,所以当我在 next() 方法中调用它时,什么也没有发生。 (下一个方法是通过代码连接到精灵生成器中的按钮调用的。)

关于 CCTextField 的第二个问题: 我在 sprite builder 的 TrialCustomization.cbb(具有 ExperimentSelection 自定义 class 代码连接)中放置了两个 CCTextField 节点,然后创建了两个文档根 var 代码连接“_blocks”和“_trials”,然后在中创建了一个变量相应的 class 具有相同名称的 CCTextField *_blocks;和 _trials 一样,但是当我给该文本字段输入时,它不会将其保存到变量中,我将它们保存到相应的方法中。

#import "CCNode.h"
@interface ExperimentSelection : CCNode
@property (nonatomic, copy) void(^whereToNext)(void);
@property CCTextField* _trials;
@property CCTextField* _blocks;

extern int trials;
extern int blocks;

-(void)patterns;

-(void)setTrialandBlock;
@end


@implementation ExperimentSelection

@synthesize whereToNext;
@synthesize  _blocks;
@synthesize  _trials;

-(void)patterns{
    whereToNext=^{
        CCScene *patternsSelection = [CCBReader loadAsScene:@"PatternsSelection"];
        [[CCDirector sharedDirector] replaceScene:patternsSelection];
        NSLog(@"Why is this code not being executed??");
   };

    NSLog(@"whereToNext: %@", whereToNext);
    [self setTrialandBlock];
}

-(void)_trials:(CCTextField*)trialsNum{
   trials=[trialsNum.string intValue];
 }

-(void)_blocks:(CCTextField*)blocksNum{
    blocks=[blocksNum.string intValue];
 }

-(void)setTrialandBlock{

    CCScene *customizeExperiment = [CCBReader      loadAsScene:@"TrialCustomization"];
    [[CCDirector sharedDirector] replaceScene:customizeExperiment];

    NSLog(@"blocks: %i, trials: %i",blocks, trials);
}

-(void)next{
    NSLog(@"wherearewegoingnext: %@, blocks: %i, trials: %i",whereToNext, blocks, trials);
    whereToNext();
}

@end

您确定 -(void)patterns 叫什么吗?

如果是,请尝试更改

void(^whereToNext)(void);

@property(nonatomic, copy) void(^whereToNext)(void);

UPD

我认为块的创建和块的执行都没有问题。我认为代码中存在一些逻辑问题。可能存在一些重载 "patterns" 方法的父或子 class。您可以在 属性 whereToNext 添加断点,然后查看此 属性 已更改。