Ich muss eine Anwendung für Schulprojekt, dass wir eine Bibliothek von PDF mit Kategorien und eine Detailansicht einer ausgewählten PDF erhalten müssen. Das Problem ist, dass, wenn ich eine Kategorie auswählen, die Anwendung abstürzt und ich diesen Fehler "fataler Fehler: unerwartet gefunden Null beim Entpacken eines optionalen Werts" Ich habe festgestellt, dass, wenn ich Daten für diese Ansicht neu lade, dass es abstürzt. Die Linie, wo ich den Fehler ist Open.target = self.revealViewController()
self.revealViewController() Fehler zurück
Hier ist meine gesamte Datei:
//
// TableViewControllertest.swift
// ProjetSwift
//
// Created by geoffrey dalfin on 08/04/2016.
// Copyright © 2016 geoffrey dalfin. All rights reserved.
//
import UIKit
import Alamofire
class TableViewControllertest: UITableViewController {
@IBOutlet weak var titrePDF: UILabel!
@IBOutlet weak var Open: UIBarButtonItem!
@IBOutlet weak var titleView: UINavigationItem!
var TabPDF = [Dictionary<String, AnyObject>]()
var selectedCategorie = String("")
override func viewDidLoad() {
if selectedCategorie == "" {
loadDataPDF()
} else {
LoadPDFCateorie(selectedCategorie)
}
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
Open.target = self.revealViewController() ***<== ERROR COMES FROM HERE***
//Quand on clique dessus, sa on appele le revealViewController
Open.action = Selector("revealToggle:")
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
func loadDataPDF(){
Alamofire.request(.GET, "http://perso.montpellier.epsi.fr/~geoffrey.dalfin/ProjetE4/requetes/ListePDF.php").responseJSON{
response in switch response.result{
case.Success:
if let PDF = response.result.value as? [Dictionary<String, AnyObject>]{
self.TabPDF = PDF
self.tableView.reloadData()
}
case.Failure(let error):
print(error)
}
}
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return TabPDF.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellule = tableView.dequeueReusableCellWithIdentifier("cellule" ,forIndexPath: indexPath) as! TableViewCell
let P = TabPDF[indexPath.row]
cellule.titrePDF?.text = P["Nom"] as? String
return cellule
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "detail" {
var details = segue.destinationViewController as!ViewDetailPDF
var indexPath = NSIndexPath()
indexPath = self.tableView.indexPathForSelectedRow!;
details.test = ((TabPDF[indexPath.row] as! [String: AnyObject]))
}
}
func LoadPDFCateorie(categorie : String){
print(categorie)
Alamofire.request(.GET, "http://perso.montpellier.epsi.fr/~geoffrey.dalfin/ProjetE4/requetes/RequeteCategorie.php?categorie="+categorie).responseJSON{
response in switch response.result{
case.Success:
print(String(response.result.value))
if let PDF = response.result.value as? [Dictionary<String, AnyObject>]{
self.TabPDF = PDF
self.tableView.reloadData()
}
case.Failure(let error):
print(error)
}
}
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
/* override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if (segue.identifier == "detail") {
// pass data to next view
var nextScene = segue.destinationViewController as! ViewDetailPDF
if let indexPath = self.tableView.indexPathForSelectedRow! {
// Pass the selected object to the new view controller
let selectedPDF = TabPDF[indexPath.row]
nextScene.DetailPDF = selectedPDF
}
}
}*/
/* override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { // Fonction pour passer des données d'un controller à un autre
let destViewController : ViewDetailPDF = segue.destinationViewController as! ViewDetailPDF
let selectedIndex = self.tableView.indexPathForCell(sender as! UITableViewCell)
destViewController.DetailPDF = TabPDF // On fait passer nos notes
}*/
}
i in eine Datei mit der Funktion haben, aber es hat sich von einem Freund mit einem Plugin, so hoffe ich das entwickelt ist der gute Teil der Datei:
@protocol SWRevealViewControllerDelegate<NSObject>
@optional
// The following delegate methods will be called before and after the front view moves to a position
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position;
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position;
// This will be called inside the reveal animation, thus you can use it to place your own code that will be animated in sync
- (void)revealController:(SWRevealViewController *)revealController animateToPosition:(FrontViewPosition)position;
können Sie den Code für 'revealViewController()' – Cjay
Welche Version von 'SWRevealViewController' verwenden Sie? – Sulthan