Search code examples
iosobjective-cuitableviewparse-platformwatchkit

Pass data from Parse tableview to WatchKit


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: enter image description here

TableVC: enter image description here

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?


Solution

  • 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.