【发布时间】:2014-04-04 11:51:57
【问题描述】:
我正在开发一个带有 uiwebview 的应用程序,并且在该 webview 中,当 uiwebview 通过 java 调用本机方法时,我需要加载本地 pdf 文件。我成功了,但是当我浏览 webisete 活动指示器时显示良好,但是当本机函数调用并且我在 uiwebview 中加载 pdf 时,它在从 url 加载 pdf 时不显示。让我在这里发布我的代码。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize webPage;
- (BOOL) shouldAutorotate{
return NO;
}
- (void)viewDidLoad
{
[super viewDidLoad];
webLink = @"http://url.com/m/";
liNk = webLink;
[webPage loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:liNk]]];
webPage.backgroundColor = [UIColor blackColor];
//[[webPage.subviews objectAtIndex:0] setBounces:NO];
[(UIScrollView*)[webPage.subviews objectAtIndex:0] setShowsVerticalScrollIndicator:NO];
[webPage addSubview:activity];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(loading) userInfo:nil repeats:YES];
webPage.delegate = self;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[[request URL] absoluteString] hasPrefix:@"ios:"]) {
// Call the given selector
[self performSelector:@selector(webToNativeCall)];
return NO;
}
return YES;
}
- (void)webToNativeCall
{
NSString *pdfurl = @"http://url.com/mypdf.pdf";
NSData *pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:pdfurl]];
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:@"mypdf.pdf"];
[pdfData writeToFile:filePath atomically:YES];
// Now create Request for the file that was saved in your documents folder
NSURL *url = [NSURL fileURLWithPath:filePath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webPage setUserInteractionEnabled:YES];
[webPage setDelegate:self];
[webPage loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
【问题讨论】:
-
我没有得到你的代码的完整流程。但是如果你使用的是 UIActivityIndicatorView,试试 [activity startAnimating];显示活动指示器和[活动停止动画];停止
-
感谢您的回复。我这样做了,但仍然没有显示活动指示器我什至尝试使用状态栏默认指示器,即使它不能正常工作。
标签: ios objective-c uiwebview uiactivityindicatorview