TableViewCell.swift
swift
1import UIKit 2 3class TableViewCell: UITableViewCell { 4 func longPressView(sender: UILongPressGestureRecognizer) { 5 print("長押し") 6 let actionSheet = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: UIAlertControllerStyle.actionSheet) 7 8 let action1 = UIAlertAction(title: "アクション1", style: UIAlertActionStyle.default, handler: { 9 (action: UIAlertAction!) in 10 print("アクション1をタップした時の処理") 11 }) 12 13 let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: { 14 (action: UIAlertAction!) in 15 print("キャンセルをタップした時の処理") 16 }) 17 18 actionSheet.addAction(action1) 19 actionSheet.addAction(cancel) 20 21 self.present(actionSheet, animated: true, completion: nil) 22 23 } 24 @IBOutlet weak var testbutton: UIButton! 25 func longbutton() { 26 let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(TableViewCell.longPressView(sender:))) 27 longPressGesture.minimumPressDuration = 0.1 28 longPressGesture.allowableMovement = 30 29 testbutton.addGestureRecognizer(longPressGesture) 30 } 31 override func awakeFromNib() { 32 super.awakeFromNib() 33 // Initialization code 34 } 35 36 override func setSelected(_ selected: Bool, animated: Bool) { 37 super.setSelected(selected, animated: animated) 38 39 // Configure the view for the selected state 40 } 41 42} 43
TableViewController.swift
swift
1import UIKit 2 3class TableViewController: UITableViewController { 4 private let myItems: NSArray = ["TEST1", "TEST2", "TEST3"] 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 } 8 9 /* 10 Cellの総数を返す. 11 */ 12 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 13 return myItems.count 14 } 15 16 /* 17 Cellに値を設定する 18 */ 19 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 20 // 再利用するCellを取得する. 21 let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! TableViewCell 22 23 // Cellに値を設定する. 24 cell.longbutton() 25 26 return cell 27 } 28} 29
このコードを書いたのですが、
TableViewCell.swift 内でこのエラーが出てしまいます。
対処法をご教授お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/24 02:27
2017/08/24 02:35
2017/08/24 04:02
2017/08/24 04:05
2017/08/24 05:32
2017/08/24 06:58 編集