0

我正在尝试使用 parse.com 数据浏览器在我的代码中插入一个新的字符串数组。

因此,如果我有一个包含 @"blue"、@"yellow"、@"black"、nil 数组的代码,那么我该如何将其更改为 @"white"、@"gold"、@"brown",无?

在应用程序中,我让用户按下一个按钮,其中一个所述字符串值随机出现。我想在后端放置一个新数组以获得新值,这样我就不必每次都更新应用程序。

有如何做到这一点的例子吗?我无法让数据浏览器将代码中的数组替换为数据浏览器中的数组。

我有:

PFQuery *query = [PFQuery queryWithClassName:@"colorArray"]; 
self.colors = [query findObjects];

但是,当我尝试检索数组的值时,它会在稍后的方法中到达这部分代码时崩溃 -

NSUInteger index = arc4random_uniform(self.colors.count]; 
self.colorLabel.text = [self.colors objectAtIndex:index];

顺便说一下,self.colors 是从头文件合成为一个数组。看起来代码在尝试使用 obectAtIndex 设置 self.colorLabel.text 时不理解等式的“索引”部分

崩溃是“-[PFObject 长度]:无法识别的选择器发送到实例 0xcb56740”。

我这样做对吗?

4

2 回答 2

1

self.colors is an array of PFObjects - not NSStrings

That is why this line fails:

self.colorLabel.text = [self.colors objectAtIndex:index];

What you need is something like:

NSUInteger index = arc4random_uniform(self.colors.count]; 
PFObject *colourPFObject = [self.colors objectAtIndex:index];
self.colorLabel.text = [colourPFObject objectForKey:@"columnNameForColour"];

Don't forget to change columnNameForColour to whatever name you call your colour column in your the Parse.com colorArray class

于 2013-09-30T11:47:21.443 回答
0

请参阅@Carl Veazey 评论。

 {colors = (Red,Blue,Black);}

来自 PFObject 的描述方法,您需要使用 PFObject 的访问器方法来获取颜色(或颜色数组)。

于 2013-09-29T21:17:23.420 回答