没有界面构建器的uiwebview(uiwebview without interface builder)

编程入门 行业动态 更新时间:2024-10-24 20:22:53
没有界面构建器的uiwebview(uiwebview without interface builder)

我要切换我的应用程序的一部分:我将实现一个图片的web查看(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!

最满意答案

在你的h文件中声明:

UIWebView *contentWebView;

并告诉您的viewController您将实现<UIWebViewDelegate>

在viewDidLoad中添加:

contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; contentWebView.delegate = self; contentWebView.multipleTouchEnabled = YES; contentWebView.scalesPageToFit = NO; [self.view addSubview:contentWebView];

在dealloc中不要忘记发布webView:

[contentWebView release];

并实现委托方法:

#pragma mark - #pragma mark WebViewDelegates - (void)webViewDidStartLoad:(UIWebView *)webView{ } - (void)webViewDidFinishLoad:(UIWebView *)webView{ } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ }

而且您还需要加载请求。 将webView添加到视图后,可以在viewDidLoad中执行以下操作:

[contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]];

Declare in your h file:

UIWebView *contentWebView;

And also tell to your viewController that you will implement <UIWebViewDelegate>

In viewDidLoad Add:

contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; contentWebView.delegate = self; contentWebView.multipleTouchEnabled = YES; contentWebView.scalesPageToFit = NO; [self.view addSubview:contentWebView];

In dealloc don't forget to release the webView:

[contentWebView release];

And implement the delegate methods:

#pragma mark - #pragma mark WebViewDelegates - (void)webViewDidStartLoad:(UIWebView *)webView{ } - (void)webViewDidFinishLoad:(UIWebView *)webView{ } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ }

And also you need to load an request. You can doit in viewDidLoad after you have added the webView to your view:

[contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]]];

更多推荐

本文发布于:2023-08-04 22:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423302.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:界面   uiwebview   builder   interface

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!