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

时间:2015-06-17 04:03:00

标签: ios objective-c uitextfield spritebuilder

我正在使用精灵构建器和Xcode。

有没有人知道我的代码块出了什么问题" whereToNext"属性?我试图用它在场景之间导航,但由于某种原因,即使它进入模式方法,它也不会进入 - (void)模式的初始化代码。因为它永远不会进入whereToNext = ^ {}代码,所以当我在next()方法中调用它时,没有任何反应。 (下一个方法是通过与sprite构建器中的按钮的代码连接来调用的。)

作为关于CCTextField的第二个问题: 我在精灵构建器上的TrialCustomization.cbb(具有ExperimentSelection自定义类代码连接)中放置了两个CCTextField节点,然后创建了两个doc root var code connection" _blocks"和" _trials"然后在相应的类中创建一个具有相同名称的变量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

1 个答案:

答案 0 :(得分:0)

您确定调用了-(void)patterns吗?

如果是,请尝试更改

void(^whereToNext)(void);

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

UPD

我认为创建块或执行块没有问题。我认为代码中存在一些逻辑问题。可能存在一些超载“模式”方法的父类或子类。您可以在属性whereToNext和视图中添加断点,然后更改此属性。