2016-03-23 9 views
0

テーブルビューのセル内のビューをクリックすると表示されるポップオーバーを作成しようとしています。これまで私が試したことは次のとおりです。 これは私が私のcustomcellの内側に持っているものです。Popview Segueを作成してテーブルビューのセル内のビューをクリックする

else if segue.identifier == "openingHours" { 
     var vc = segue.destinationViewController 
     var controller = vc.popoverPresentationController 
     if controller != nil { 
      controller?.delegate = self 
     } 
    } 

@IBAction func openingHoursTap(sender: UITapGestureRecognizer) { 
    performSegueWithIdentifier("openingHours", sender: self) 
} 


func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
    return .None 
} 

識別子が正しい:

class Cell: UITableViewCell { 

@IBOutlet weak var openingHoursView: CustomView! 

override func awakeFromNib() { 
    super.awakeFromNib() 
    let tap = UITapGestureRecognizer(target: self, action: Selector("openingHoursTap:")) 
    openingHoursView.addGestureRecognizer(tap) 
} 

override func setSelected(selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 
} 
} 

これは私が私のビューコントローラの内部で持っているものです。アンカーは、セグエのテーブルビューです。以前はタップ可能なビューを実際に作成したことはありませんでしたが、ボタンで同じことをやっただけでうまくいきました。エラーは発生せず、ビューをクリックするとアプリがクラッシュするだけです。

私は、個々のセルのcellForRowAtIndexPathにそれを追加しないことが私には関係していると推測しています。 addTargetを使用できない場合、これはビューでどのように行われますか?

+0

あなたはopeningHoursTap '呼び出している:あなたのテーブルセルに'が、openingHoursTap 'のあなたの実際の実装は:'あなたのビューコントローラの右にありますか? – TangZijian

+0

正しい、私のテーブルビュー内でそれを実装しようとしている – luke

答えて

0

テーブルビューのセルでopeningHoursTap:を呼び出していますが、実際の実装はビューコントローラにあります。それがクラッシュする理由です。したがって、これを行う正しい方法は、ビューコントローラのtableView: cellForRowAtIndexpath:にタップジェスチャ認識機能を追加することです。

例:

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")
let tap = UITapGestureRecognizer(target: self, action:Selector("openingHoursTap:"))
cell.openingHoursView.addGestureRecognizer(tap)
}

+0

ああええ、cellForRowAtIndexpathに追加する方法を見つけることができませんでした。ありがとうございます – luke

+0

あなたは歓迎します。 – TangZijian

関連する問題