Webview в Какао не загружается - PullRequest
0 голосов
/ 28 декабря 2011

Сохраняется ошибка выдачи: Тип получателя webFrame для сообщения экземпляра является предварительным объявлением в строке"[[webView mainFrame] loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: urlStr]]];"

мой .h файл

@interface AttendanceWizardAppDelegate : NSObject <NSApplicationDelegate> 
{
@private WebView *webView;

} 
@property (weak) IBOutlet WebView *webView;
@property (assign) IBOutlet NSWindow *window;

@end

Мой .m файл

#import "AttendanceWizardAppDelegate.h"

@implementation AttendanceWizardAppDelegate


@synthesize Username = _Username;
@synthesize Password = _Password;
@synthesize webView = _webView;
@synthesize webber = _webber;
@synthesize window = _window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *urlStr = @"www.google.com";
[[webView mainFrame ] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
}

@end

1 Ответ

2 голосов
/ 28 декабря 2011

Вам просто нужно добавить импорт заголовков WebKit в ваш файл заголовка:

#import <WebKit/WebKit.h>

Ваш код также можно упростить, не определяя переменную экземпляра для объявленных вами свойств:

Заголовочный файл (.h):

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface AttendanceWizardAppDelegate : NSObject <NSApplicationDelegate> 
// No need for a iVar declaration

@property (weak) IBOutlet WebView *webView;
@property (assign) IBOutlet NSWindow *window;

@end

Файл реализации (.m):

#import "AttendanceWizardAppDelegate.h"

@implementation AttendanceWizardAppDelegate

// Simplified synthesize declarations (no reference to the iVar)
@synthesize Username; // I suggest you change the name of this variable ; the convention is to start the name of your property with a lower case letter, to not confuse it with a class name
@synthesize Password;
@synthesize webView;
@synthesize webber;
@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSString *urlString = @"www.google.com";

    [[self.webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]]; // Note the use of self.webView, to use the getter you created by declaring the property
}

@end
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...