【发布时间】:2014-04-08 07:14:43
【问题描述】:
我是 iOS 新手。我想在 iOS 中添加 PDF 文档。我尝试了两种选择。 iOS 中的 URL 和文档。但是当我尝试使用 URL 打开 PDF 时,我得到空页面。当我尝试使用 pdf 文档时,我在 Xcode 上遇到错误。
我试试这个网址
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize screenSize = rect.size;
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
NSURL *targetURL = [NSURL URLWithString:@"http://dokuman.osym.gov.tr/pdfdokuman/2012/OSYS/2012YGSSorular.pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
我试试这个做文档
NSString *path = [[NSBundle mainBundle] pathForResource:@"document" ofType:@"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
是关于故事板的吗?因为我不用.xib
我收到此错误。
2014-03-06 01:38:49.635 YGS[3934:70b] * 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“只有在源控制器由UINavigationController 的实例。 * 首先抛出调用栈: ( 0 CoreFoundation 0x017395e4 异常预处理 + 180 1 libobjc.A.dylib 0x014bc8b6 objc_exception_throw + 44 2 UIKit 0x0076eca5-[UIStoryboardPushSegue destinationContainmentContext] + 0 3 UIKit 0x0075f07e-[UIStoryboardSegueTemplate _perform:] + 174 4 UIKit 0x0075f0f9 -[UIStoryboardSegueTemplate 执行:] + 115 5 libobjc.A.dylib 0x014ce874-[NSObject performSelector:withObject:withObject:] + 77 6 UIKit 0x0022c0c2-[UIApplication sendAction:to:from:forEvent:] + 108 7 UIKit 0x0022c04e-[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61 8 UIKit 0x003240c1-[UIControl sendAction:to:forEvent:] + 66 9 UIKit 0x00324484-[UIControl_sendActionsForEvents:withEvent:] + 577 10 UIKit 0x00323733-[UIControl touchesEnded:withEvent:] + 641 11 UIKit 0x0059ec7f _UIGestureRecognizerUpdate + 7166 12 UIKit 0x0026919a-[UIWindow_sendGesturesForEvent:] + 1291 13 UIKit 0x0026a0ba -[UIWindow 发送事件:] + 1030 14 UIKit 0x0023de86 -[UIApplication 发送事件:] + 242 15 UIKit 0x0022818f _UIApplicationHandleEventQueue + 11421 16 核心基础 0x016c283f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15 17 核心基础 0x016c21cb __CFRunLoopDoSources0 + 235 18 核心基础 0x016df29e __CFRunLoopRun + 910 19 核心基础 0x016deac3 CFRunLoopRunSpecific + 467 20 核心基础 0x016de8db CFRunLoopRunInMode + 123 21 图形服务 0x036de9e2 GSEventRunModal + 192 22 图形服务 0x036de809 GSEventRun + 104 23 UIKit 0x0022ad3b UIApplicationMain + 1225 24 YGS 0x0000305d 主 + 141 25 libdyld.dylib 0x01d77701 开始 + 1 26 ??? 0x00000001 0x0 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)
【问题讨论】:
-
我复制粘贴了你的代码,它对我来说很好用。你确定
[self.view addSubview:webView]吗?并仔细检查您的互联网连接。此外,它是一个 52 页的文档,因此在连接速度较慢的情况下,可能需要一段时间才能加载。 -
绝对分享错误。
-
等了 2 小时,但没有成功。是关于 .storyboard 的吗?因为我不使用.xib。