2014-11-24 81 views
2

昨天我參加了watchkit hackathon,在調用NSObject類的方法時遇到了一些問題,該類使用Google Maps API併發送本地通知。如果我把這個方法從我Watchkit擴展,代碼不編譯,但如果我從視圖控制器打電話,例如,一切完美在Watchkit上調用方法

#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 

我得到的錯誤是: Error

+0

你有沒有想過這個? – you786 2015-04-27 02:28:38

回答

8

檢查您的Methods類的目標,並確保它在您的手錶套件擴展目標中。

enter image description here

或者,看看建設共享類的框架。 https://developer.apple.com/videos/wwdc/2014/?id=416

+0

同樣的事情發生了。我會看到你發送的鏈接/ – 2014-11-25 18:24:53

1

我不知道您使用的xcode版本,但考慮到initWithContext方法不再有效。你應該使用:

- (void)awakeWithContext:(id)context 

而你不應該覆蓋它,只是使用它。

0

只是刪除#import行並將其替換爲WatchKit框架。