Swift2 如何使tableview可剪裁,以便它可以将我带到另一个页面?

Swift2 如何使tableview可剪裁,以便它可以将我带到另一个页面?,swift2,xcode7.1,Swift2,Xcode7.1,这是我到目前为止的代码,但我想让它可以点击。一旦你点击一个项目,它可以带你到另一个页面 import UIKit import CoreData class ViewController: UIViewController,UITableViewDataSource { @IBOutlet weak var tableView: UITableView! var people = [NSManagedObject]() @IBAction func addName(sender: Any

这是我到目前为止的代码,但我想让它可以点击。一旦你点击一个项目,它可以带你到另一个页面

import UIKit
import CoreData

class ViewController: UIViewController,UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!

var people = [NSManagedObject]()

@IBAction func addName(sender: AnyObject) {
    let alert = UIAlertController(title: "New Client",
        message: "Add a new client",
        preferredStyle: .Alert)

    let saveAction = UIAlertAction(title: "Save",
        style: .Default,
        handler: { (action:UIAlertAction) -> Void in

            let textField = alert.textFields!.first
            self.saveName(textField!.text!)


            self.tableView.reloadData()
    })

    let cancelAction = UIAlertAction(title: "Cancel",
        style: .Default) { (action: UIAlertAction) -> Void in
    }

    alert.addTextFieldWithConfigurationHandler {
        (textField: UITextField) -> Void in
    }

    alert.addAction(saveAction)
    alert.addAction(cancelAction)

    presentViewController(alert,
        animated: true,
        completion: nil)
}


override func viewDidLoad() {
    super.viewDidLoad()
    title = "Clients"
    tableView.registerClass(UITableViewCell.self,
        forCellReuseIdentifier: "Cell")

}

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

func tableView(tableView: UITableView,
    cellForRowAtIndexPath
    indexPath: NSIndexPath) -> UITableViewCell {

        let cell =
        tableView.dequeueReusableCellWithIdentifier("Cell")

        let person = people[indexPath.row]

        cell!.textLabel!.text =
            person.valueForKey("name") as? String


        return cell!
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func saveName(name: String) {
    //1
    let appDelegate =
    UIApplication.sharedApplication().delegate as! AppDelegate

    let managedContext = appDelegate.managedObjectContext

    //2
    let entity =  NSEntityDescription.entityForName("Person",
        inManagedObjectContext:managedContext)

    let person = NSManagedObject(entity: entity!,
        insertIntoManagedObjectContext: managedContext)

    //3
    person.setValue(name, forKey: "name")


    //4
    do {
        try managedContext.save()
        //5
        people.append(person)
    } catch let error as NSError  {
        print("Could not save \(error), \(error.userInfo)")
    }
}
override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    //1
    let appDelegate =
    UIApplication.sharedApplication().delegate as! AppDelegate

    let managedContext = appDelegate.managedObjectContext

    //2
    let fetchRequest = NSFetchRequest(entityName: "Person")


    //3
    do {
        let results =
        try managedContext.executeFetchRequest(fetchRequest)
        people = results as! [NSManagedObject]
    } catch let error as NSError {
        print("Could not fetch \(error), \(error.userInfo)")
    }
}


}

您可以将视图控制器设置为tableView委托,并实现tableView:DidSelectRowatineXpath:以显示新的页面视图控制器或执行一个序列。您的类定义变为:

class ViewController: UIViewController,UITableViewDataSource, UITableViewDelegate {
  // your existing code
    func tableView(_ tableView: UITableView,didSelectRowAtIndexPath indexPath: NSIndexPath) {
        // either present the view controller for new page or perform the Segue
    }
}

将表格视图选择样式设置为“无选择”,并使用点击手势使表格视图可点击。