【问题标题】:Calling a Method on Watchkit在 Watchkit 上调用方法
【发布时间】:2014-11-24 19:35:01
【问题描述】:

我昨天参加了一个 watchkit 黑客马拉松,在调用 NSObject 类的方法时遇到了一些问题,该类使用 Google Maps API 并发送本地通知。如果我从我的 Watchkit 扩展中调用此方法,代码不会编译,但如果我从 ViewController 调用,例如,一切正常

#import "InterfaceController.h"
#import "Methods.h"

@interface InterfaceController()

 @end


 @implementation InterfaceController

- (instancetype)initWithContext:(id)context {
self = [super initWithContext:context];
if (self){
    // Initialize variables here.
    // Configure interface objects here.
    NSLog(@"%@ initWithContext", self);

}
return self;
}
- (IBAction)butRoute
{
     Methods *mt = [[Methods alloc]init];
    [mt notif:@"ARRIVING!"];
    //***** If I call this method, my code won't compile!!! *****

}

- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
NSLog(@"%@ will activate", self);
}

- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
NSLog(@"%@ did deactivate", self);
}

@end

我得到的错误是:

【问题讨论】:

  • 你有想过这个吗?

标签: objective-c watchkit


【解决方案1】:

检查您的方法类的目标,并确保它在您的手表套件扩展目标中。

或者,考虑为您的共享类构建一个框架。 https://developer.apple.com/videos/wwdc/2014/?id=416

【讨论】:

  • 同样的事情发生了。我会看到你发送的链接/
【解决方案2】:

我不知道您使用的是什么 xcode 版本,但考虑到 initWithContext 方法不再有效。你应该使用:

- (void)awakeWithContext:(id)context

而且你不应该覆盖它,只是使用它。

【讨论】:

    【解决方案3】:

    只需删除 #import 行并将其替换为 WatchKit 框架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      • 2012-02-05
      • 2015-01-16
      相关资源
      最近更新 更多