跟踪按钮上的点击?
Keep track of taps on a button?
有没有办法记录用户点击按钮的次数?我希望在用户多次点击按钮后执行 segue。截至目前,我正在让我的后端跟踪点击了多少次。
@IBAction func nextbuttontest(sender: AnyObject) {
let button = sender as! UIButton
let view = button.superview!
let cell = view.superview as! NewFeedControllerCell
let indexPath = tableView.indexPathForCell(cell)
let row = indexPath?.row
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0),
atScrollPosition: UITableViewScrollPosition.Top,
animated: false)
}
您可以在视图控制器中创建整数变量,并将其用作计数器 -> 也就是说,当用户点击时增加它,如果点击次数足够多,则执行 segue 或其他操作。
例如:
var tapCounter = 0
作为视图控制器中的声明。
func tapGestureForElement(gest:UIGestureRecognizer){
tapCounter = tapCounter + 1
if(tapCounter == 123){
//performSegue
}
}
编辑::
第二部分:
if(row!+1 == yourArray.count){ // or == 10, as you mentioned in comments, but I think that is a bad practice
//do nothing or do something, up to you :)
{
else{
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
}
编辑 2:
你甚至可以做得更好,你可以检查你是否到达了部分行的末尾:
if( row!+1 == tableView. numberOfRowsInSection(indexPath.section)
最后一部分没有测试,但应该是这样。
如 NickCatib 所说,将 tapCounter
属性 添加到您的视图控制器。但是,不是在点击计数达到所需值时手动触发 segue,而是覆盖 shouldPerformSegueWithIdentifier:sender:
以便在达到点击计数之前它不会 return YES
对于该特定的 segue .
有没有办法记录用户点击按钮的次数?我希望在用户多次点击按钮后执行 segue。截至目前,我正在让我的后端跟踪点击了多少次。
@IBAction func nextbuttontest(sender: AnyObject) {
let button = sender as! UIButton
let view = button.superview!
let cell = view.superview as! NewFeedControllerCell
let indexPath = tableView.indexPathForCell(cell)
let row = indexPath?.row
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0),
atScrollPosition: UITableViewScrollPosition.Top,
animated: false)
}
您可以在视图控制器中创建整数变量,并将其用作计数器 -> 也就是说,当用户点击时增加它,如果点击次数足够多,则执行 segue 或其他操作。
例如:
var tapCounter = 0
作为视图控制器中的声明。
func tapGestureForElement(gest:UIGestureRecognizer){
tapCounter = tapCounter + 1
if(tapCounter == 123){
//performSegue
}
}
编辑::
第二部分:
if(row!+1 == yourArray.count){ // or == 10, as you mentioned in comments, but I think that is a bad practice
//do nothing or do something, up to you :)
{
else{
tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: row!+1, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
}
编辑 2:
你甚至可以做得更好,你可以检查你是否到达了部分行的末尾:
if( row!+1 == tableView. numberOfRowsInSection(indexPath.section)
最后一部分没有测试,但应该是这样。
如 NickCatib 所说,将 tapCounter
属性 添加到您的视图控制器。但是,不是在点击计数达到所需值时手动触发 segue,而是覆盖 shouldPerformSegueWithIdentifier:sender:
以便在达到点击计数之前它不会 return YES
对于该特定的 segue .