gpt4 book ai didi

ios - 在辅助 View Controller 上显示来自网站的 pdf

转载 作者:行者123 更新时间:2023-11-28 14:59:27 25 4
gpt4 key购买 nike

我的应用程序中有多个列表,现在我想在用户单击某个单元格时显示来自网站的 pdf。我很好奇我可以在我的 ListView 代码中实现什么代码来将信息传递给辅助 Controller ,该 Controller 将在 UIWebView(?) 而不是图像中显示 pdf。

我喜欢编辑以发送 pdf 而不是列表中的图像的代码 ID 是:

import UIKit
import GoogleMobileAds


class tablelist: UIViewController, UITableViewDataSource, UITableViewDelegate, GADBannerViewDelegate {

var bannerView: GADBannerView!


override func viewDidLoad(){
super.viewDidLoad()

self.navigationController?.navigationBar.barTintColor = UIColor.black
let textAttributes = [NSForegroundColorAttributeName:UIColor.red]
navigationController?.navigationBar.titleTextAttributes = textAttributes




self.animalTableView.dataSource = self
self.animalTableView.delegate = self
self.view.backgroundColor = UIColor.black


//--------------------------LIST STUFF-------------------------------------------------------//

let respiratory = ["Cat", "Dog", "Cow", "Mulval"]



@IBOutlet weak var animalTableView: UITableView!

///Set elements in cell
func tableView( _ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "adultresplist"/*Identifier*/, for: indexPath)
cell.textLabel?.text = respiratory[indexPath.row]
// FONT STYLE
cell.textLabel?.textColor = UIColor.white
cell.detailTextLabel?.font = UIFont.boldSystemFont(ofSize: 30.0)
cell.textLabel?.textAlignment = .center
self.animalTableView.backgroundColor = UIColor.clear
cell.textLabel?.backgroundColor = UIColor.black

return cell
}

///Return Count

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return respiratory.count
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{

let Vc = self.storyboard?.instantiateViewController(withIdentifier: "imageViewController") as! imageViewController


switch indexPath.row
{
case 0:
Vc.passedImage = UIImage.init(named: "image1")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 1:
Vc.passedImage = UIImage.init(named: "image2")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 2:
Vc.passedImage = UIImage.init(named: "image3")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 3:
Vc.passedImage = UIImage.init(named: "image1")!
self.navigationController?.pushViewController(Vc, animated: true)
break;
default:
Vc.passedImage = UIImage.init(named: "image2")!
self.navigationController?.pushViewController(Vc, animated: true)
}
}
}
}

我在辅助 Controller 中显示图像的代码是:

 class pdfviewer: UIViewController,GADBannerViewDelegate, UIGestureRecognizerDelegate, UIScrollViewDelegate, UIWebViewDelegate {

var bannerView: GADBannerView!

var pdfUrl: UIWebView! = nil


@IBOutlet weak var webView: UIWebView!


func loadPdfWithUrl(url: URL)
{
webView.loadRequest(URLRequest(url: url))
}

func webViewDidFinishLoad(_ webView: UIWebView)
{
if (webView.isLoading)
{
let contentSize:CGSize = webView.scrollView.contentSize
let viewSize:CGSize = self.view.bounds.size

let rw : CGFloat = viewSize.width / contentSize.width

webView.scrollView.minimumZoomScale = rw
webView.scrollView.maximumZoomScale = rw
webView.scrollView.zoomScale = rw
}
}

最佳答案

从 WebView 中的链接加载 Pdf 的示例代码

在您的 TableList 中

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let Vc = self.storyboard?.instantiateViewController(withIdentifier: "pdfVC") as! pdfVC

switch indexPath.row
{
case 0:
Vc.pdfUrl = URL.init(string: "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf")
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 1:
Vc.pdfUrl = URL.init(string: "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf")
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 2:
Vc.pdfUrl = URL.init(string: "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf")
self.navigationController?.pushViewController(Vc, animated: true)
break;
case 3:
Vc.pdfUrl = URL.init(string: "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf")
self.navigationController?.pushViewController(Vc, animated: true)
break;
default:
Vc.pdfUrl = URL.init(string: "http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf")
self.navigationController?.pushViewController(Vc, animated: true)
break;
}

}

在 pdf Controller 中

func loadPdfWithUrl(url: URL)
{
webView.loadRequest(URLRequest(url: url))
}

func webViewDidFinishLoad(_ webView: UIWebView)
{
if (webView.isLoading)
{
let contentSize:CGSize = webView.scrollView.contentSize
let viewSize:CGSize = self.view.bounds.size

let rw : CGFloat = viewSize.width / contentSize.width

webView.scrollView.minimumZoomScale = rw
webView.scrollView.maximumZoomScale = rw
webView.scrollView.zoomScale = rw
}
}

Storyboard:

enter image description here

示例代码文件

链接 - https://drive.google.com/open?id=1HmSnGFEGAbPLFdAcUzdbpodAm6gfXbmm

关于ios - 在辅助 View Controller 上显示来自网站的 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49079650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com