每次触摸屏幕都会更新 plist 中的文本

发布于 2024-10-21 22:43:57 字数 1541 浏览 4 评论 0原文

我正在从 plist 中搜索一些短语,并希望每次触摸时都将此类语句更新到屏幕上,但我找不到问题的解决方案,因此我请求帮助以了解如何实现此目的,我的代码如下。

int RecordIndexDitados = 0;

NSMutableArray *dictDitados;

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Ditados.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

NSDictionary *ditados = [plistData objectForKey:@"Ditados"];
NSMutableArray *selection = [[ditados objectForKey:@"Selection"] mutableCopy];

RecordIndexDitados = arc4random()%[selection count];

// Select and display currently selected record from the array.
dictDitados = [selection objectAtIndex:RecordIndexDitados]

CCLabel *ditados = [CCLabel labelWithString:@"Question" 
                                     dimensions:CGSizeMake(400, 200)
                                      alignment:UITextAlignmentCenter
                                       fontName:@"Brush Script" fontSize:36];
    ditados.color = ccc3(0, 74, 128);
    [ditados setPosition:ccp(240, 120)];
    [self addChild: ditados];
    [ditados setString:[NSString stringWithFormat:@"%@",dictDitados]];

<plist version="1.0">
<dict>
    <key>Ditados</key>
    <dict>
        <key>Selection</key>
        <array>
            <string>Text 1</string>
            <string>Text 2</string>
            <string>Text 3</string>     
        </array>
    </dict>
</dict>
</plist>

I'm searching for some phrases from a plist, and would like to update such statements to the screen every touch, but I can not find a solution to the problem, so I ask help on how to implement this, my code is below.

int RecordIndexDitados = 0;

NSMutableArray *dictDitados;

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Ditados.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

NSDictionary *ditados = [plistData objectForKey:@"Ditados"];
NSMutableArray *selection = [[ditados objectForKey:@"Selection"] mutableCopy];

RecordIndexDitados = arc4random()%[selection count];

// Select and display currently selected record from the array.
dictDitados = [selection objectAtIndex:RecordIndexDitados]

CCLabel *ditados = [CCLabel labelWithString:@"Question" 
                                     dimensions:CGSizeMake(400, 200)
                                      alignment:UITextAlignmentCenter
                                       fontName:@"Brush Script" fontSize:36];
    ditados.color = ccc3(0, 74, 128);
    [ditados setPosition:ccp(240, 120)];
    [self addChild: ditados];
    [ditados setString:[NSString stringWithFormat:@"%@",dictDitados]];

<plist version="1.0">
<dict>
    <key>Ditados</key>
    <dict>
        <key>Selection</key>
        <array>
            <string>Text 1</string>
            <string>Text 2</string>
            <string>Text 3</string>     
        </array>
    </dict>
</dict>
</plist>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻安 2024-10-28 22:43:57

为什么不将 plist 加载到内存中并从那里更新内容呢?这样您只需从 plist 加载一次数据..而不是每次触摸屏幕时。

why don't you load your plist in memory and update your content from there? this way you load your data from the plist only once..not every time you touch the screen.

清风无影 2024-10-28 22:43:57

1st 将 plist 的内容读入您设计的 plist 中的一些临时对象(字符串、数组或目录)。

第二知道将更新的值插入到临时对象中。

第三将临时对象分配给主对象。

第四步将主对象写入文件。

为了您更好地理解,请参阅:

http://iphonesdevsdk.blogspot.com/2011/04 /plist.html

它可能对你有帮助。

1st read the contents of plist into some temp object(string,array or directory) as you designed plist.

2nd know insert the updated value into temp object.

3rd assign the temp object to main object.

4th write the main object into file.

For your better understanding refer this like:

http://iphonesdevsdk.blogspot.com/2011/04/plist.html

it may helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文