對於Objective C來說還是比較新的,而且我之前沒有使用過MVC系統。NSApplication沒有明顯的@interface聲明選擇器openURL
我試圖重定向到通過默認瀏覽器的URL,這裏是相關的代碼:
AppDelegate.h
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
...
- (IBAction)about:(id)sender;
...
@end
聲明動作
AppDelegate.m
@implementation AppDelegate
...
- (IBAction)about:(id)sender {
NSURL *web_url = [NSURL URLWithString:@"http://www.someurl.com/"];
[[NSApplication sharedApplication] openURL:web_url]; // error location
}
...
@end
在按鈕上執行操作點擊關於:
IDE錯誤:NSApplication沒有可見的@interface聲明選擇器openURL
什麼似乎是問題?
'IBAction'在App Delegate?你應該把'IBAction'放在視圖控制器/視圖中。 – Raptor