ios - 将数据从 Parse tableview 传递到 WatchKit

标签 ios objective-c uitableview parse-platform watchkit

我正在使用Parse创建此 TableView ,并试图弄清楚如何获取表数据,以便我可以将其传递到WatchKit InterfaceController.

(我是否需要查询 Parse 以某种方式获取数据并将其存储在 array 中,然后我就可以从 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;
}

解析数据: enter image description here

表VC: enter image description here

我确实设置了基本的 WKInterfaceTable,我所需要做的就是让它显示与 TableVC.m 相同的精确数据。

所以我陷入困境的是,我知道我需要在 WKInterfaceTable 中使用某种数组,但在我的 TableVC.m 中我使用 Parse 我无法弄清楚如何/做什么才能让它发生。看起来我可能会在 viewDidLoad 中执行解析查询,以提取相同的相应 testdateTime 以在 WKInterfaceTable 中使用,但是我不知道?

最佳答案

在您的 WatchKit 扩展中,您需要以不同的方式设置表格。在 iOS 上,UITableView 会根据单元格的需要查询您的数据源。在 WatchKit 上,您需要一次将表格的所有数据传递给 WKInterfaceTable。我不打算在这里详细介绍如何设置你的 table ,因为你可以在这里找到一些很好的信息 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html .

此外,我建议您在后台执行解析查询,然后在数据返回后更新您的表。

关于ios - 将数据从 Parse tableview 传递到 WatchKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28398721/

相关文章:

iOS:使用类型 'CGRect'(又名 'struct CGRect'),其中需要算术或指针类型

ios - 在 UIScrollView 中嵌入 UIStackView 时出现问题

objective-c - NSDate和NSDateComponents返回错误的日期

iOS - UIScrollView 中的按钮点击动画

ios - 具有自动布局的 UIScrollview

ios - 通过其他按钮隐藏单元格中的按钮按下uitableview

ios - UINavigationItem titleView定位问题

ios - 以编程方式在 plist 文件中添加索引

swift - 如何更正自定义单元格中计时器倒计时中数字的跳过?

ios - 如何在选择时禁用单元格的颜色