Pass data from Parse tableview to WatchKit

非 Y 不嫁゛ 提交于 2019-12-02 20:33:04

问题


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.

(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?)

Here is what I have, let me know if I can add anything that would be helpful:

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:

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.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/28398721/pass-data-from-parse-tableview-to-watchkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!