带界面生成器的iPhone SDK UIWebView
我很难完成一些听起来很简单的事情。使用Interface Builder,我创建了一个UIWebView对象。接下来,我创建了一个新的控制器——HomeViewController,并在“NIB名称”属性下将其分配给WebView。 接下来,当用户访问该视图时,我需要将一个网站(比方说)加载到该web视图中。我找不到任何关于如何真正做到这一点的例子。请提供一个代码示例。很抱歉我问了个新手问题。我做了RTFM,但运气不好。试试这个:带界面生成器的iPhone SDK UIWebView,iphone,cocoa-touch,uiwebview,Iphone,Cocoa Touch,Uiwebview,我很难完成一些听起来很简单的事情。使用Interface Builder,我创建了一个UIWebView对象。接下来,我创建了一个新的控制器——HomeViewController,并在“NIB名称”属性下将其分配给WebView。 接下来,当用户访问该视图时,我需要将一个网站(比方说)加载到该web视图中。我找不到任何关于如何真正做到这一点的例子。请提供一个代码示例。很抱歉我问了个新手问题。我做了RTFM,但运气不好。试试这个: [webview loadRequest:[NSURLReque
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]]; // webview - your Uiwebview object
试试这个:
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]]; // webview - your Uiwebview object
.h文件:
@interface WebViewController : UIViewController {
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) UIWebView *webView;
@end
.m文件:
#import "WebViewController.h"
@implementation WebViewController
// Loads the url when the view loads
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
@end
.h文件:
@interface WebViewController : UIViewController {
IBOutlet UIWebView *webView;
}
@property (nonatomic, retain) UIWebView *webView;
@end
.m文件:
#import "WebViewController.h"
@implementation WebViewController
// Loads the url when the view loads
- (void)viewDidLoad {
NSString *urlAddress = @"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Request Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
}
@end
你能提供这方面的背景吗?这是怎么回事,“webview”对象从何而来?这是一个基于nib的UIWebView对象,那么如何在代码中引用它呢?在.h文件中为UIWebView创建IBoutlet,并在nib文件中连接它。例如ibuiwebview*webview;你能提供这方面的背景吗?这是怎么回事,“webview”对象从何而来?这是一个基于nib的UIWebView对象,那么如何在代码中引用它呢?在.h文件中为UIWebView创建IBoutlet,并在nib文件中连接它。例如ibuiwebview*webview;这些引文都是乱七八糟的,但我不能编辑这篇文章,因为它至少需要编辑6个字符:/。复制粘贴程序,如果出现错误,请更改质量。除此之外,它工作得很好,+1。那些引用都是乱七八糟的,但我不能编辑这篇文章,因为它至少需要编辑6个字符:/。复制粘贴程序,如果出现错误,请更改质量。除此之外,它工作得非常完美,+1。