こんな感じかな?
lang
1import UIKit
2
3class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
4
5 @IBOutlet weak var tableView: UITableView!
6 var array : Array<String> = []
7
8 override func viewDidLoad() {
9 super.viewDidLoad()
10
11 self.tableView.delegate = self
12 self.tableView.dataSource = self
13
14 array = ["1", "2", "3", "4", "5", "6"]
15
16 let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: "rowButtonAction:")
17 longPressRecognizer.allowableMovement = 15
18 longPressRecognizer.minimumPressDuration = 0.6
19 self.tableView .addGestureRecognizer(longPressRecognizer)
20
21 }
22
23 func rowButtonAction(sender : UILongPressGestureRecognizer) {
24
25 let point: CGPoint = sender.locationInView(tableView)
26 let indexPath = tableView.indexPathForRowAtPoint(point)
27
28 if let indexPath = indexPath {
29 if sender.state == UIGestureRecognizerState.Began {
30
31 // セルが長押しされたときの処理
32 println("long pressed \(indexPath.row)")
33 }
34 }else{
35 println("long press on table view")
36 }
37 }
38
39 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
40 return array.count
41 }
42
43 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
44 let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
45 cell.textLabel?.text = array[indexPath.row]
46 return cell
47 }
48
49 override func didReceiveMemoryWarning() {
50 super.didReceiveMemoryWarning()
51 // Dispose of any resources that can be recreated.
52 }
53}