将数据从Parse tableview传递到WatchKit [英] Pass data from Parse tableview to WatchKit
问题描述
我正在使用 Parse
创建此表视图,并试图弄清楚如何获取表数据,以便可以将其传递给WatchKit > InterfaceController
.
I'm using Parse
to create this table view, and am trying to figure out how to get the table data, so I can pass it into the WatchKit InterfaceController
.
(我是否需要查询Parse
以某种方式获取并将数据存储在array
中,然后可以从WatchKit InterfaceController
awakeWithContext
调用它?)
(Would I need to query Parse
to somehow get and store the data in an array
which I would then be able to call from the WatchKit InterfaceController
awakeWithContext
?)
这里是我所拥有的,请告诉我是否可以添加任何有帮助的内容:
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
数据:
TableVC
:
我确实有基本的WKInterfaceTable
设置,我要做的就是让它显示与TableVC.m
相同的确切数据.
I do have the the basic WKInterfaceTable
set up, and all I need to do is have it show the same exact data as the TableVC.m
.
所以我遇到的困难是,我知道我需要在WKInterfaceTable
中使用某种类型的数组,但是在我使用Parse
的TableVC.m
中,我无法弄清楚如何/如何做才能做到这一点.似乎我可能会在viewDidLoad中执行解析查询,以提取相同的相应test
和dateTime
以便在WKInterfaceTable
中使用,但是我不确定吗?
So where I'm stuck is that I know I need an array of some sort in the WKInterfaceTable
to use, but in my TableVC.m
where I use Parse
I'm not able to figure out how/what to do to get that to happen. And it seems like I would probably do a parse query in my viewDidLoad to pull the same corresponding test
and dateTime
for use in the WKInterfaceTable
, but I'm not sure?
推荐答案
在WatchKit扩展中,您需要以其他方式设置表.在iOS上,UITableView根据单元格的需要查询您的数据源.在WatchKit上,您需要一次将一个表的所有数据传递给您WKInterfaceTable
.我不会在这里详细介绍如何设置表格,因为您可以在此处找到一些不错的信息
In you WatchKit extension you need to set up your table differently. On iOS the UITableView queries your datasource as needed for cells. On WatchKit you need to pass all of the data for a table at one time to you WKInterfaceTable
. I am not going to go into detail here for how to set up you table as you can find some great info here https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html.
此外,我建议您在后台执行解析查询,然后在数据返回后更新表.
Also, I would suggest that you do your parse query in the background and then update your table after the data has returned.
这篇关于将数据从Parse tableview传递到WatchKit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!