我想在我的程序中显示网页,我在我的 IB (.xib) 中使用 WebView 对象,但它不起作用,是否有任何示例代码,而不是文档或文章?
view_w.h
@interface view_w : NSObject {
IBOutlet WebView* Web;
}
-(IBAction) google:(id) sender;
@end
view_w.m
-(IBAction) google:(id) sender
{
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[Web loadrequest:request];
}
//错误 No -loadrequest: 找到方法
最佳答案
您应该将 webview 连接到 View Controller 类的 socket 。然后
NSURL *url = [NSURL URLWithString:@"http://yoursite.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[yourwebviewoutlet loadRequest:request];
仅此而已。
编辑以抑制有关未找到方法的警告,请正确指定类型:
IBOutlet UIWebView * web; // and use lowercase for variables while you're at it.
关于objective-c - 我如何使用cocoa中的webview对象来显示网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3429964/