从 Parse 查询中获取数组
Get an array from Parse query
我正在使用 Parse
创建此 table 视图,并且正在尝试弄清楚如何将 Parse
table 数据放入数组中,所以我可以将它传递到 WatchKit InterfaceController
以显示完全相同的东西吗?
所以我想在WatchKit界面中显示在iPhone界面中显示的内容。
这是我的所有内容,如果我可以添加任何有用的内容,请告诉我:
TableVC.m
:
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = @"na";
self.textKey = @"dateTime";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
}
return self;
}
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
UILabel *homeLabel = (UILabel*) [cell viewWithTag:101];
homeLabel.text = [object objectForKey:@"test"];
UILabel *dateLabel = (UILabel*) [cell viewWithTag:102];
dateLabel.text = [object objectForKey:@"dateTime"];
return cell;
}
Parse data
:
TableVC.m
:
我已经设置了基本的 WatchKit
文件和故事板。我硬编码了一个数组来测试它是否正常工作。但是现在我只需要从 Parse
中获取数据,并且不确定是否需要进行查询然后将其转换为 public array
?
编辑:
这是我的查询:
PFQuery *query2 = [PFQuery queryWithClassName:@"nba"];
[query2 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Objects 2: %@", objects);
}
} else {
// Log details of the failure
NSLog(@"Error 2: %@ %@", error, [error userInfo]);
}
}];
这是我的 NSLog:
NSLog(@"Objects 2: %@", objects);
控制台:
2015-02-09 21:06:30.845 SimpleTable[8373:1284663] Objects 2: (
"<na: 0x7ff3f8e40880, objectId: cOrjeAmwJh, localId: (null)> {\n away = Cav;\n date = \"04/19/2015\";\n dateTime = \"April 19, 2015, 16:00\";\n gNumber = 1;\n home = Bul;\n matup = \"Ca\";\n ro = \"Ro \";\n test = \"Test 2\";\n tv = T;\n}",
如果您只想将对象传递到一个数组中,您可以像这样或变体这样做:
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
self.someArray = [query findObjects];
return query;
}
参考
如果你需要这个数组,在queryForTable
方法之外的方法异步获取它,像这样获取它这个:
PFQuery *query = [self queryForTable];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// objects is the array for this table
NSMutableArray *array = [@[] mutableCopy];
for (PFObject *object in objects) {
NSLog(@"we got an object with dateTime = %@", [object objectForKey:@"dateTime"]);
[array addObject:[object objectForKey:@"dateTime"]];
// you can prove this with any of your keys: away, number, home, mat up, etc.
}
}
}];
我正在使用 Parse
创建此 table 视图,并且正在尝试弄清楚如何将 Parse
table 数据放入数组中,所以我可以将它传递到 WatchKit InterfaceController
以显示完全相同的东西吗?
所以我想在WatchKit界面中显示在iPhone界面中显示的内容。
这是我的所有内容,如果我可以添加任何有用的内容,请告诉我:
TableVC.m
:
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = @"na";
self.textKey = @"dateTime";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
}
return self;
}
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
UILabel *homeLabel = (UILabel*) [cell viewWithTag:101];
homeLabel.text = [object objectForKey:@"test"];
UILabel *dateLabel = (UILabel*) [cell viewWithTag:102];
dateLabel.text = [object objectForKey:@"dateTime"];
return cell;
}
Parse data
:
TableVC.m
:
我已经设置了基本的 WatchKit
文件和故事板。我硬编码了一个数组来测试它是否正常工作。但是现在我只需要从 Parse
中获取数据,并且不确定是否需要进行查询然后将其转换为 public array
?
编辑:
这是我的查询:
PFQuery *query2 = [PFQuery queryWithClassName:@"nba"];
[query2 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Objects 2: %@", objects);
}
} else {
// Log details of the failure
NSLog(@"Error 2: %@ %@", error, [error userInfo]);
}
}];
这是我的 NSLog:
NSLog(@"Objects 2: %@", objects);
控制台:
2015-02-09 21:06:30.845 SimpleTable[8373:1284663] Objects 2: (
"<na: 0x7ff3f8e40880, objectId: cOrjeAmwJh, localId: (null)> {\n away = Cav;\n date = \"04/19/2015\";\n dateTime = \"April 19, 2015, 16:00\";\n gNumber = 1;\n home = Bul;\n matup = \"Ca\";\n ro = \"Ro \";\n test = \"Test 2\";\n tv = T;\n}",
如果您只想将对象传递到一个数组中,您可以像这样或变体这样做:
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
self.someArray = [query findObjects];
return query;
}
参考
如果你需要这个数组,在queryForTable
方法之外的方法异步获取它,像这样获取它这个:
PFQuery *query = [self queryForTable];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// objects is the array for this table
NSMutableArray *array = [@[] mutableCopy];
for (PFObject *object in objects) {
NSLog(@"we got an object with dateTime = %@", [object objectForKey:@"dateTime"]);
[array addObject:[object objectForKey:@"dateTime"]];
// you can prove this with any of your keys: away, number, home, mat up, etc.
}
}
}];