【问题标题】:Pass data from Parse tableview to WatchKit将数据从 Parse tableview 传递到 WatchKit
【发布时间】:2015-02-08 20:01:42
【问题描述】:

我正在使用 Parse 来创建这个表格视图,并试图弄清楚如何获取表格数据,以便将其传递给 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;
}

Parse 数据:

TableVC:

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

所以我卡住的地方是我知道我需要在WKInterfaceTable 中使用某种数组,但是在我使用ParseTableVC.m 中我无法弄清楚如何/怎么做才能实现。似乎我可能会在我的 viewDidLoad 中进行解析查询,以提取相同的相应 testdateTime 以在 WKInterfaceTable 中使用,但我不确定?

【问题讨论】:

  • 你有没有想过解决这个问题?
  • @user717452 不,有什么想法吗?

标签: ios objective-c uitableview parse-platform watchkit


【解决方案1】:

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

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

【讨论】:

  • 感谢您的回复!我确实设置了基本的WKInterfaceTable。所以我卡住的地方是我知道我需要在WKInterfaceTable 中使用某种数组,但是在我使用ParseTableVC.m 中,我无法弄清楚如何/做什么得到那个。似乎您在说可能在我的viewDidLoad 中进行解析查询以提取testdateTime 以在WKInterfaceTable 中使用?我基本上只想要我的WKInterfaceTable 中的相同数据。
  • 你需要在你的PFQuery对象上调用findObjects来获取你的数组。然后您需要使用[table setNumberOfRows:results.count withRowType:@"MyRowTypeClass"]; 设置WKInterfaceTable 上的行数,然后您需要遍历从findObjects 返回的结果中的每个结果并调用MyRowTypeClass* row = [table rowControllerAtIndex:index];。然后,您可以从解析查询的结果中设置值。您需要使用 IBOutlets 将 MyRowTypeClass 设置为您自己的类,并使用情节提要进行布局。
  • 我有 MyRowTypeClass 和 IBOutlets 和 Storyboard 设置,很高兴知道我正在跟踪它。我是否在“TableVC.m”中执行 PFQuery 等?或者我可以在WKInterfaceTable 中做到这一点吗?因为如果它在TableVC.m 中,那么我需要将其保存为公共array,以便我的WKInterfaceTable 可以正确使用它,还是我对此的想法有误?
  • 我不是 100% 确定我了解您的代码结构,但据我了解,您会希望在 TableVC.m 中有一个出口到您的 WKInterfaceTable 并在您的 TableVC 中进行查询。然后在插座上为 WKInterfaceTable 设置数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-14
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多