Well, my problem is as follows. I have the entire app made with two Viewcontroller. The problem is that the whole app is developing well, except when displaying the PDF cell in the second screen that does not appear at all. What can I miss? This is the code of the second ViewController where I have a web view from the first, and linked by a Segue: import UIKit import WebKit
class ViewController2: UIViewController, WKUIDelegate {
@IBOutlet var VistaWebPdf: WKWebView!
var nombrePdfRecibido: String?
var vistaWebPdf: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
VistaWebPdf = WKWebView(frame: .zero, configuration: webConfiguration)
VistaWebPdf.uiDelegate = self
view = VistaWebPdf
var vistaWebPdf: WKWebView!
var nombrePdfRecibido:String?
func viewDidLoad() {
super.viewDidLoad()
mostrarPdf()
}
}
func mostrarPdf(){
//1 Dirección del archivo PDF
let nombrePdfRecibido = "PDF"
let direccionPdf = URL(fileURLWithPath: Bundle.main.path(forResource: nombrePdfRecibido, ofType: "Pdf", inDirectory: "PDF")!)
// 2 Transform PDF file to Data
let datosPdf = try? Data(contentsOf: direccionPdf )
// 3 Display Data in the Web View
VistaWebPdf.load (dataPdf !, mimeType: "application / pdf", characterEncodingName: "utf-8", baseURL: direccionPdf)
}
}
AFTER, I PUT THE CODE OF VIEWCONTROLLER 1 together with the Navigation Controller: //
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var contenidoCeldas = ["PDF1","PDF2","PDF3","PDF4","PDF5","PDF6","PDF7","PDF8"]
@IBOutlet var tabla: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tabla.dataSource = self
tabla.delegate = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contenidoCeldas.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print(indexPath.section)
let celda = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier:"CellPDF")
celda.textLabel?.text = contenidoCeldas[indexPath.row]
return celda
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
_ = indexPath.row
self.performSegue(withIdentifier: "Pantalla_2Segue"){
}
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Pantalla_2Segue" {
let iPdfSeleccionadoRecibido = sender as! NSIndexPath
let idx = iPdfSeleccionadoRecibido.row
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Pantalla_2Segue" {
let idPdfSeleccionadoRecibido = sender as! NSIndexPath
let idx = idPdfSeleccionadoRecibido.row
let objPantalla2:ViewController2 = segue.destination as! ViewController2
objPantalla2.nombrePdfRecibido = contenidoCeldas[idx]
}
}
}