2017-03-08 5 views
1

私は、2つのボタンとtableViewを持つダイアログをポップアップするボタンがあります。 tableViewはカスタムUIViewを使用して表示され、UITableViewCellもカスタムです。 UITableViewCellは、カスタムチェックボックスとUILabelで構成されています。テーブルビューにタップジェスチャーを追加しようとしています。その行をクリックすると、チェックボックスがマークされます。私はもっ​​として3秒間押すと、この機能は、ちょっと作品のが、UITableViewCellのは、このエラーの原因となっていただきました!私は知らないこのSwift UiTableViewCellメインのView Controllerで長押しの後にリセット

UITableViewCell Error ScreenShot

にリセットされます。どんな助けもありがとう。私はあなたがタップジェスチャーを追加する必要があるかもしれないと思う

override func viewDidLoad() { 
    super.viewDidLoad() 

    ...code 

    let tap = UITapGestureRecognizer(target: self, action: #selector(tableTapped)) 
    self.tableView.addGestureRecognizer(tap) 
} 

func tableTapped(tap:UITapGestureRecognizer) { 
    let location = tap.location(in: self.tableView) 
    let path = self.tableView.indexPathForRow(at: location) 
    if let indexPathForRow = path { 
     self.tableView(self.tableView, didSelectRowAt: indexPathForRow) 
     print("Tapped on the table") 
    } else { 
     // handle tap on empty space below existing rows however you want 
    } 
} 

答えて

0

:のtableViewと私のカスタムのUIViewに

func locationButtonPressed(sender: UIBarButtonItem) { 
    // Create a custom view controller 
    let vc = RadiusViewController(nibName: "RadiusViewController", bundle: nil) 
    // Create the dialog 
    let popup = PopupDialog(viewController: vc, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true) 

    // create first button 
    let cancelButton = CancelButton(title: "Cancel", height: 60, dismissOnTap: true) { 
     print("Popup Canceled") 
    } 

    // create second button 
    let okButton = DefaultButton(title: "Ok", height: 60, dismissOnTap: true) { 
     print("Ok button pressed") 
    } 

    // add buttons to dialog 
    popup.addButtons([cancelButton, okButton]) 

    // present dialog 
    self.present(popup, animated: true, completion: nil) 

    print("location button pressed") 
} 

タップジェスチャー機能:ここで

は、ポップアップダイアログを開き、私のViewControllerで私のコードですあなたのtableviewcellではなく、tableview。

+0

どうすればいいですか? – satish99

0

あなたのViewControllerにUITableViewDelegateを実装するだけでよいのです。 didSelectRowAtIndexPathのコールバックメソッドがあり、カスタムチェックボックスなどのセルのプロパティにアクセスするロジックを設定できます。これはネイティブに提供される機能であるため、タップジェスチャ認識機能は不要です。

UITableViewDelegate Documentation

関連する問題