将数据从 Parse tableview 传递到 WatchKit [英] Pass data from Parse tableview to WatchKit

查看:16
本文介绍了将数据从 Parse tableview 传递到 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;
}

解析数据:

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 中使用某种数组,但是在我的 TableVC.m 中我使用 Parse 我不知道如何/如何做才能实现这一点.似乎我可能会在我的 viewDidLoad 中进行解析查询以提取相同的相应 testdateTime 以在 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.我不会在这里详细介绍如何设置你的表,因为你可以在这里找到一些很好的信息 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆