将数据从 Parse tableview 传递到 WatchKit
Pass data from Parse tableview to WatchKit
我正在使用 Parse
创建此 table 视图 ,并且正在尝试弄清楚 如何获取 table 数据,所以我可以将它传递到 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
中使用某种数组,但在我的 TableVC.m
中我使用 Parse
我'我无法弄清楚 how/what 要做到这一点。似乎我可能会在我的 viewDidLoad 中执行解析查询以提取相同的对应 test
和 dateTime
用于 WKInterfaceTable
,但我不确定?
在您的 WatchKit 扩展中,您需要以不同的方式设置 table。在 iOS 上,UITableView 会根据单元格的需要查询您的数据源。在 WatchKit 上,您需要一次性将 table 的所有数据传递给您 WKInterfaceTable
。我不会在这里详细介绍如何设置您 table,因为您可以在此处找到一些重要信息 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html。
此外,我建议您在后台执行解析查询,然后在数据返回后更新 table。
我正在使用 Parse
创建此 table 视图 ,并且正在尝试弄清楚 如何获取 table 数据,所以我可以将它传递到 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
中使用某种数组,但在我的 TableVC.m
中我使用 Parse
我'我无法弄清楚 how/what 要做到这一点。似乎我可能会在我的 viewDidLoad 中执行解析查询以提取相同的对应 test
和 dateTime
用于 WKInterfaceTable
,但我不确定?
在您的 WatchKit 扩展中,您需要以不同的方式设置 table。在 iOS 上,UITableView 会根据单元格的需要查询您的数据源。在 WatchKit 上,您需要一次性将 table 的所有数据传递给您 WKInterfaceTable
。我不会在这里详细介绍如何设置您 table,因为您可以在此处找到一些重要信息 https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/Tables.html。
此外,我建议您在后台执行解析查询,然后在数据返回后更新 table。