如何将数据从解析保存到NSArray

如何将数据从解析保存到NSArray

本文介绍了如何将数据从解析保存到NSArray iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何以以下格式将数据从解析保存到NSArray.用于填充UITableView,用于搜索栏.

How can I save data from parse to an NSArray in the below format. which is being used to populate a UITableView, which is to be used for a search bar.

_candyArray = [NSArray arrayWithObjects:
                  [Candy candyOfCategory:@"chocolate" name:@"chocolate bar" mName:@"test1"],
                  [Candy candyOfCategory:@"chocolate" name:@"chocolate chip" mName:@"test1"],
                  [Candy candyOfCategory:@"chocolate" name:@"dark chocolate" mName:@"test1"],
                  [Candy candyOfCategory:@"hard" name:@"lollipop" mName:@"test1"],
                  [Candy candyOfCategory:@"hard" name:@"candy cane" mName:@"test1"],
                  [Candy candyOfCategory:@"hard" name:@"jaw breaker" mName:@"test1"],
                  [Candy candyOfCategory:@"other" name:@"caramel" mName:@"test1"],
                  [Candy candyOfCategory:@"other" name:@"sour chew" mName:@"test1"],
                  [Candy candyOfCategory:@"other" name:@"peanut butter cup" mName:@"test1"],
                  [Candy candyOfCategory:@"other" name:@"gummi bear" mName:@"test1"], nil];

我尝试了下面的代码,但是id没有加载任何数据,当我通过NSLog

I tried the below code, but id didn't load any data, keeps returning the value as null when I run it through NSLog

PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query orderByAscending:@"Name"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        {
            self.arrayName = objects;
        }
    }else {
        NSLog(@"Error, %@ %@",error,[error userInfo]);
    }
}];

NSLog(@"Array : %@", arrayName);

反正有没有将数据保存在上述类型的数组中?

Is there anyway to save the data in the above type of array?

推荐答案

为空的原因是

findObjectsInBackgroundWithBlock

尚未完成.如果要处理结果(或记录结果),则需要将log语句放入块中,或者可以使用

is not finished when that log statement is run. If you want to handle the results (or log them), you need to put the log statement inside the block, or you can use

findObjectsInBackgroundWithTarget:selector:

相反,并在回调方法中包含处理代码.

instead, and have the handling code in your callback method.

这篇关于如何将数据从解析保存到NSArray iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:15