Hi there:
I have no idea what happens to my App, because I was trying to run an App Reader but I don´t know how to show PDfs on second screen, it was connected by segue and they are not displayed as usual.
Pues mi problema es el siguiente. Tengo toda la app realizada con dos Viewcontroller. EL problema es que toda la app se desarrolla bien, menos al mostrar la celda de Pdf en la segunda pantalla que no aparece nada. ¿Qué me puede faltar? Este es el código del segundo ViewController donde tengo puesta una vista web desde el primero, y enlazado por un 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 Transformar archivo PDF a Data
let datosPdf = try? Data(contentsOf: direccionPdf )
//3 Mostrar Datos en la Vista Web
VistaWebPdf.load(datosPdf!, mimeType: "application/pdf", characterEncodingName: "utf-8", baseURL: direccionPdf)
}
}
Viewcontroller 1 shown:
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]
}
}
}