Ios 为什么我的代码块实例变量没有初始化并打印出一个";NSGlobalBlock";?
我正在使用sprite builder和Xcode 有人看到我的代码块“whereToNext”属性哪里出错了吗?我试图使用它在场景之间导航,但由于某种原因,它没有进入-(void)模式中的初始化代码,即使它进入模式方法。因为它从不进入whereToNext=^{}代码,所以当我在next()方法中调用它时,什么都不会发生。(下一个方法是通过与sprite builder中的按钮的代码连接调用的。) 关于CCTextField的第二个问题: 我在sprite builder上的TrialCustomization.cbb(具有ExperimentSelection自定义类代码连接)中放置了两个CCTextField节点,然后创建了两个文档根var代码连接“\u blocks”和“\u trials”,然后在相应的类中创建了一个名为CCTextField*\u blocks的变量;对于_试验也是一样,但当我输入文本字段时,它不会保存到变量中,我在相应的方法中保存了变量Ios 为什么我的代码块实例变量没有初始化并打印出一个";NSGlobalBlock";?,ios,objective-c,uitextfield,spritebuilder,Ios,Objective C,Uitextfield,Spritebuilder,我正在使用sprite builder和Xcode 有人看到我的代码块“whereToNext”属性哪里出错了吗?我试图使用它在场景之间导航,但由于某种原因,它没有进入-(void)模式中的初始化代码,即使它进入模式方法。因为它从不进入whereToNext=^{}代码,所以当我在next()方法中调用它时,什么都不会发生。(下一个方法是通过与sprite builder中的按钮的代码连接调用的。) 关于CCTextField的第二个问题: 我在sprite builder上的TrialCust
#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)模式
如果是,尝试改变
void(^whereToNext)(void)代码>
到
@属性(非原子,副本)无效(^whereToNext)(无效)代码>
UPD
我认为创建块或执行块没有问题。我认为代码中存在一些逻辑问题。可能存在一些重载“patterns”方法的父类或子类。您可以将断点添加到属性whereToNext和view中,然后更改此属性。在接口类中?在接口或类别中。对于私有方法,我使用类别。你在用ARC吗?这还是不起作用。一旦我在patterns方法中声明它,我就打印出一个NSLog(@“WhereToNext:%@”,WhereToNext)。我仍然得到一个地址,而不是我想要填充的内容。可能是我不明白,你是在试着打印block的内容吗?如果是,则无法创建该块,因为它是指向C结构()的指针。它不是某个脚本的字符串。您只能将其检查为nil(if(whereToNext){})哦,好的。但是当我调用whereToNext()时,代码块中的代码没有被执行,我甚至在whereToNext=^{CCScene*patternselection=[CCBReader loadAsScene:@“patternselection”];[[CCDirector sharedDirector]replaceSecene:patternselection];NSLog(@“HELLO”);};我从来没有看到过这一点。我不知道为什么括号里的代码永远都找不到?