2017-09-09 1 views
0

Pourquoi Xcode me dit-il que performSegue (withIdentifier :) est un identificateur non résolu? (S'il vous plaît voir commenté la ligne)Utilisation de l'identificateur non résolu erreur "performSegue"

import UIKit 

class AllListsViewController: UITableViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // 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() 
    } 

    // MARK: - Table view data source 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 3 
    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = makeCell(for: tableView) 
     cell.textLabel!.text = "List \(indexPath.row)" 

     return cell 
    } 
} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    performSegue(withIdentifier: "ShowChecklist", sender: nil) // Use of unresolved identifier "performSegue" 
} 

func makeCell(for tableView: UITableView) -> UITableViewCell { 
    let cellIdentifier = "Cell" 
    if let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) { 
     return cell 
    } else { 
     return UITableViewCell(style: .default, reuseIdentifier: cellIdentifier) 
    } 
} 
+0

J'ai mis à jour votre code avec un indentation appropriée. L'erreur est très claire maintenant. – rmaddy

+1

@NiravD Il n'y a pas de '}' supplémentaire. Voir le code avec indentation appropriée. – rmaddy

+0

@NiravD, vous avez presque raison, ce n'est pas un '' 'supplémentaire, mais c'est au mauvais endroit. –

Répondre

1

Vous avez une deux erreurs dans votre code:

  1. Ligne 27 } sont à la fin car cela met fin à la classe
  2. héritant de Trovit facilite UITableViewController, vous devez overridetableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

code qui compile:

import UIKit 

class AllListsViewController: UITableViewController { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // 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() 
    } 

    // MARK: - Table view data source 

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 3 
    } 

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = makeCell(for: tableView) 
     cell.textLabel!.text = "List \(indexPath.row)" 

     return cell 
    } 

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     performSegue(withIdentifier: "ShowChecklist", sender: nil) // Use of unresolved identifier "performSegue" 
    } 

    func makeCell(for tableView: UITableView) -> UITableViewCell { 
     let cellIdentifier = "Cell" 
     if let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) { 
      return cell 
     } else { 
      return UITableViewCell(style: .default, reuseIdentifier: cellIdentifier) 
     } 
    } 
}