【问题标题】:How to Push Data From one WKInterfaceController to Another?如何将数据从一个 WKInterfaceController 推送到另一个?
【发布时间】:2015-03-31 20:16:42
【问题描述】:

我的 WatchKit 中有 2 个接口控制器。第一个称为 InterfaceController,而另一个称为 DetailsForWatch。 IC上有一个tableView。它解析来自 Parse 类的数据,并将类中每个条目的数据显示为一行。这很好用。

我要做的是将所选行的 PFObject 传递给 DetailsForWatch 中的 PFObject。我对 DFW 的设置是:

.h

@interface DetailsForWatch : WKInterfaceController {
}
@property (nonatomic, retain) IBOutlet WKInterfaceLabel *detailsLabel;
@property (nonatomic, retain) PFObject *finalObject;

@end

.m

- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    NSString *details = self.finalObject [@"Request"];

    [self.detailsLabel setText:details];
    NSLog(@"%@", self.finalObject);
    // Configure interface objects here.
}

在 IC 中,对于 .h 我有:

@class DetailsForWatch;
@interface InterfaceController : WKInterfaceController {
    DetailsForWatch *_theDetails;


}
@property (retain) DetailsForWatch *theDetails;
@end

在 .m 中我有:

@synthesize theDetails = _theDetails;

对于 didSelectRowAtIndex,我有:

_theObject = _theObjective[rowIndex];

    self.theDetails = [[DetailsForWatch alloc] init];
    _theDetails.finalObject = _theObject;

我将 DFW 设置为来自 IC 组的推送选择。当我在 IC 中选择一行时,它会推送一个空白屏幕,并且 NSLog 显示名为 finalObject 的 PFObject 为(null)。我做错了什么,它没有正确传递 PFObject?

【问题讨论】:

    标签: ios objective-c watchkit wkinterfacelabel


    【解决方案1】:

    有几种方法可以在两个接口控制器之间传递数据。我一直这样做的方式是这样的:

    1. 在我的故事板中的两个控制器之间创建一个 segue(必要时给它一个标识符)。

    2. 在接口控制器 1 中实现

    - (id)contextForSegueWithIdentifier:(NSString *)segueIdentifier

    当通过按钮按下或其他方式触发 segue 时将调用它。

    这可以返回任何对象,例如数据字典(在您的情况下为“theDetails”)

    1. 在接口控制器 2 中实现

    - (void)awakeWithContext:(id)context

    这里的上下文对象将是您在控制器 1 中传递的对象

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 2020-08-23
      相关资源
      最近更新 更多