没有界面生成器的 uiwebview
我必须切换我的应用程序的一部分:我将实现一个图片视图(imageview)的网络视图。
所以我尝试用界面生成器来制作它,但是错误太多,所以我更喜欢使用代码!
对于图片,我使用这些行:
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
self.imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0,64,320,367);
[self.view addSubview:imageView];
[self.imageView release];
现在,我尝试使用此代码,但没有显示任何内容:
@property (nonatomic, retain) IBOutlet UIWebView *webView;
...
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.fr"]]];
[self.view addSubview:webView];
如果你知道如何制作...对我来说会很好,
谢谢!
I've to switch a part of my app: I will implement a web view insread of a picture (imageview).
So I tried to make it with the interface builder but there is too many errors so I prefer to use code!
for the pictures, I user those lines :
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
self.imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0,64,320,367);
[self.view addSubview:imageView];
[self.imageView release];
Now, I tried to use this code but nothing's showed:
@property (nonatomic, retain) IBOutlet UIWebView *webView;
...
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.fr"]]];
[self.view addSubview:webView];
If you know how to make .... would be nice for me,
THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的 h 文件中声明:
并告诉你的 viewController 你将实现
在 viewDidLoad 中添加:
在 dealloc 中不要忘记释放 webView:
并实现委托方法:
并且您需要加载一个请求。将 webView 添加到视图后,您可以在 viewDidLoad 中执行此操作:
Declare in your h file:
And also tell to your viewController that you will implement
<UIWebViewDelegate>
In viewDidLoad Add:
In dealloc don't forget to release the webView:
And implement the delegate methods:
And also you need to load an request. You can doit in viewDidLoad after you have added the webView to your view:
根据需要调整框架,如果添加像 imageview 这样的东西作为 webview 的子视图,那么你必须使用 Bringsubviewtofront 函数。
adjust the frame as u needed and if add anything like imageview as subview to webview then u have to use bringsubviewtofront function.