我正在使用Parse
创建此表视图,并试图找出如何将Parse
表数据转换为数组,因此我可以将其传递给{{1}显示完全相同的东西?
所以我想在WatchKit界面中显示iPhone界面中显示的内容。
以下是我所拥有的内容,如果我能添加任何有用的内容,请与我们联系:
WatchKit InterfaceController
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
文件和Storyboard。我对一个数组进行了硬编码,以测试它是否正常工作。但是现在我只需要将WatchKit
中的数据放到那里,并且不确定我是否需要进行查询然后将其转换为公开Parse
?
修改:
这是我的问题:
array
这是我的NSLog:
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(@"Objects 2: %@", objects);
答案 0 :(得分:3)
如果您需要数组,请在 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.
}
}
}];
答案 1 :(得分:0)
如果您只是想将对象传递给数组,可以像这样或者变体:
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
self.someArray = [query findObjects];
return query;
}
REFERNECE