我要切换我的应用程序的一部分:我将实现一个图片的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/"]]];更多推荐
发布评论