2016-08-10 14 views
-1

UITableViewCellが私のUITableViewにタップしていることを検出する必要があります。UITabelViewCellのタップが検出されない

これは私のコードです:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     let section = indexPath.section 
     let row = indexPath.row 
     if section == 2 && row == 0 { 
      //OTHER CODE 
     } 
} 

でもない作品を行います。

そして、これは私のUITableViewの属性インスペクタの設定は次のとおりです。

enter image description here enter image description here

EDIT:

私の完全なコード:

class UserPageWeeklyInformationsTableViewController: UITableViewController, UIWebViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { 

    //VARIABLES 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     //OTHER CODE 
    } 

    override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { 

     let header:UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView 

     let fontSize = header.textLabel!.font.pointSize 
     header.textLabel!.font = UIFont(name: "Avenir", size: fontSize) 
     header.textLabel!.frame = header.frame 
    } 

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     let section = indexPath.section 
     let row = indexPath.row 
     print(section) 
     print(row) 
     if section == 2 && row == 0 { 
      NSNotificationCenter.defaultCenter().postNotificationName("goToPost", object: nil) 
     } 
    } 
} 

EDIT:

私のUITableViewControllerは、UIViewControllerに位置するContainer Viewに含まれています。メインのUITableViewControllerではTap Gesture Recognizerを実装しています。

EDIT:

私はメインUIViewControllerにジェスチャー認識器を取り外し、問題を解決します。

+0

UITapGestureRecognizer.cancelsTouchesInView = falseの設定を試してだろうか?おそらくwillSelectRowAtIndexPathを実装しましたか? – ff10

+0

コードのセクション2は、テーブルの3番目のセクションです。正しい行をクリックしていますか? – Shades

+0

@ ff10 willSelectRowAtIndexPathを実装しませんでした。 –

答えて

1

あなたはストーリーボードに何を持っていますか?あなたは、テーブルビューがそれを受け取る前に、タップを処理しているUI要素を持つことができます。

UITableViewが認識する前に、UITapGestureRecognizerがタップジェスチャーを処理していた問題があります。

注:タップジェスチャーを削除するのではなく、あなたがdidSelectRowAtIndexPathも呼ばれてい

3

は、私はあなたがUITableViewDelegateとしてクラスを設定するかどうかをチェックすることをお勧めし、あなたのテーブルが実際にのViewControllerに埋め込まれていることなので

tableView.delegate = self 
+2

なぜ投票が否定されたのか、この回答も役立つかもしれません –

0

として設定し、あなたはそののViewControllerの出口テーブルを作成する必要がありテーブルのすべてのコードをそのVCのクラスに入れます。関数から "override"という単語が削除されていることに注意してください。

class MyViewController: UIViewController, UITableViewDelegate { 

    @IBOutlet weak var myTable: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     myTable.delegate = self 
    } 

    func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { 

     let header:UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView 

     let fontSize = header.textLabel!.font.pointSize 
     header.textLabel!.font = UIFont(name: "Avenir", size: fontSize) 
     header.textLabel!.frame = header.frame 
    } 

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     let section = indexPath.section 
     let row = indexPath.row 
     print(section) 
     print(row) 
     if section == 2 && row == 0 { 
      NSNotificationCenter.defaultCenter().postNotificationName("goToPost", object: nil) 
     } 
    } 
} 
関連する問題