Xcode 将字典链接到自定义初始化器终止-原因:'-[\uu NSCFArray isFileURL]:
请耐心点,我是个努比 我是第一次编写自定义init,sentance01text加载良好,因此我知道plist的读数正常:),但我似乎无法让我的sentance01Timing计时工作> HelloWorld.mXcode 将字典链接到自定义初始化器终止-原因:'-[\uu NSCFArray isFileURL]:,xcode,cocos2d-iphone,Xcode,Cocos2d Iphone,请耐心点,我是个努比 我是第一次编写自定义init,sentance01text加载良好,因此我知道plist的读数正常:),但我似乎无法让我的sentance01Timing计时工作>
#import "HelloWorldLayer.h"
#import "TextWithAudioHilight.h"
@implementation HelloWorldLayer
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
HelloWorldLayer *layer = [HelloWorldLayer node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init])) {
TextWithAudioHilight *pagetext = [[TextWithAudioHilight alloc]initWith5:@"test words here,\nmore words, more words.."
sentance01Timing:@"TimingSEN01"
withSoundNamed:nil];
[self addChild:pagetext];
}
return self;
}
- (void) dealloc
{
[super dealloc];
}
@end
TextWithAudio.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface TextWithAudioHilight : CCLayer {
}
@property(nonatomic,retain)NSString *sentance01text;
@property(nonatomic,retain)NSString *sentance01Timing;
@property(nonatomic,retain)NSString *soundNamed;
-(id)initWith5:(NSString *)sentance01text sentance01Timing:(NSString *)sentance01Timing withSoundNamed:(NSString *)soundNamed;
@end
音频计时
<plist version="1.0">
<dict>
<key>TimingSEN01</key>
<array>
<real>0.044444</real>
<real>0.143054</real>
<real>0.213886</real>
<real>0.48055</real>
<real>0.844434</real>
<real>1.345817</real>
<real>1.470816</real>
<real>1.577759</real>
<real>2.020809</real>
<real>2.331917</real>
</array>
</dict>
</plist>
计时SEN01
0.044444
0.143054
0.213886
0.48055
0.844434
1.345817
1.470816
1.577759
2.020809
2.331917
多亏了特洛伊木马,我才得以解决这个问题
主要的问题是我初始化的对象没有被保留
如果你确实在代码中看到了更好的方法,请说,因为我的目标是学习(但是婴儿步骤!这一切都很新!!)
我在我的旧mac笔记本电脑上做这个(所以它不是arc的——因为我现在无法测试它)
但也许它会帮助其他人
因此,创建我的textmangerclass:
@interface TextManagerWithpageNum : CCLayer
{
//create the properties you need notice the underscore
//NSString *_varName;
NSString *_background;
NSString* _text; //myText
NSString* _soundFile;
NSString* _audioInterval;
NSString* _currPageNumber;
}
声明@property,该属性允许访问值访问器(getter)和mutator(setter)
和执行
//@synthesize varName = _varName;
@synthesize background = _background;
@synthesize text = _text;
@synthesize soundFile = _soundFile;
@synthesize audioInterval = _audioInterval;
@synthesize currPageNumber = _currPageNumber;
-(id)initWithBackground:(NSString *)background
textFromPlist:(NSString *)text
soundNamed:(NSString *)soundFile
audioIntervalPlist:(NSString *)audioInterval
CurrentPage:(NSString *)currPageNumber
{
self = [super init];
if(self)
{
//_varName = varName;
_text = text;
_audioInterval = audioInterval;
_soundFile = soundFile;
_currPageNumber = currPageNumber;
/*here is where I was having the problem - its important to manually retain
and dealloc or you wont be able to use your objects created!*/
//audio interval
_audioInterval= [[myDictionary objectForKey:audioInterval]retain];//***please retain me! and dont forget to dealloc! :)
NSLog(@"audio Intervals %@",audioInterval);
你好,世界
TextManagerWithpageNum *Mypage =
[[TextManagerWithpageNum alloc]initWithBackground:@"Page01Bg.png"textFromPlist:@"Page01Text"soundNamed:@"Page01" audioIntervalPlist:@"AudioTimings" CurrentPage:5];
[self addChild:Mypage];
//希望我塞满东西的练习例子能帮助其他人
因为从别人的错误中学习更有趣:Phmmm这将是我对如何获取用户键入的内容以及如何传递我一直坚持的内容的理解。。。我会更新代码并解释我的思考过程(因为很可能是错误的:P),谢谢你的关注:)对不起,我的评论太离谱了。我需要更多的信息。
\u语句01计时
包含哪些内容?是否为文件名(如果是,请更好地命名变量)。另外,请发布行的其余部分开始终止-原因:'-[\uu NSCFArray isFileURL]:
!:
后面是什么?更多的困惑。你说你想使用用户输入的值,但你正在从文件中读取值?!?如果您使用[NSArray arraywhithcontentsoffile:
加载音频间隔,您会意识到用户需要输入一个有效的文件名吗?噢,您对无法识别的选择器的胡言乱语,我还以为您是个读心术的人呢!已将无法识别的选择器发送到实例0x6820e20'。我会在一秒钟内发布所有的代码。对不起,当我说用户(只有我)一个糟糕的词语选择时,我只是创建了一个类,我可以通过在字典中键入艺术作品、声音等的val来快速链接到plists和artwork-对不起,我不是有意混淆。我会加载项目)那会更快
//@synthesize varName = _varName;
@synthesize background = _background;
@synthesize text = _text;
@synthesize soundFile = _soundFile;
@synthesize audioInterval = _audioInterval;
@synthesize currPageNumber = _currPageNumber;
-(id)initWithBackground:(NSString *)background
textFromPlist:(NSString *)text
soundNamed:(NSString *)soundFile
audioIntervalPlist:(NSString *)audioInterval
CurrentPage:(NSString *)currPageNumber
{
self = [super init];
if(self)
{
//_varName = varName;
_text = text;
_audioInterval = audioInterval;
_soundFile = soundFile;
_currPageNumber = currPageNumber;
/*here is where I was having the problem - its important to manually retain
and dealloc or you wont be able to use your objects created!*/
//audio interval
_audioInterval= [[myDictionary objectForKey:audioInterval]retain];//***please retain me! and dont forget to dealloc! :)
NSLog(@"audio Intervals %@",audioInterval);
TextManagerWithpageNum *Mypage =
[[TextManagerWithpageNum alloc]initWithBackground:@"Page01Bg.png"textFromPlist:@"Page01Text"soundNamed:@"Page01" audioIntervalPlist:@"AudioTimings" CurrentPage:5];
[self addChild:Mypage];