Ios 如何传递额外的参数
我需要使用Ios 如何传递额外的参数,ios,swift,uitableview,parameter-passing,uigesturerecognizer,Ios,Swift,Uitableview,Parameter Passing,Uigesturerecognizer,我需要使用ui长按GestureRecognitor的选择器传递第二个参数 let lpGestureRecognizer: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressCell)) 我需要把长时间按下的手机也发送出去。有什么办法吗 如果该函数有如下两个参数,请提前感谢 func clicked(sender:AnyObject,
ui长按GestureRecognitor的
选择器传递第二个参数
let lpGestureRecognizer: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressCell))
我需要把长时间按下的手机也发送出去。有什么办法吗
如果该函数有如下两个参数,请提前感谢
func clicked(sender:AnyObject,value:AnyObject)
{
}
然后
例如:
func switchCard(card: Int, withCard card1: Int)
{
print(card)
}
let singleTap1 = UITapGestureRecognizer(target: self, action: "switchCard:withCard:")
请注意Swift 2.2。现在可以按以下方式键入选择器:
#selector(popoverSelectedCode(_:desc:)
如果函数有如下两个参数
func clicked(sender:AnyObject,value:AnyObject)
{
}
然后
例如:
func switchCard(card: Int, withCard card1: Int)
{
print(card)
}
let singleTap1 = UITapGestureRecognizer(target: self, action: "switchCard:withCard:")
请注意Swift 2.2。现在可以按以下方式键入选择器:
#selector(popoverSelectedCode(_:desc:)
我假设您的意思是希望将视图发送到动作函数,并且将手势添加到该视图中 在这种情况下,您只需从传递给动作函数的手势中获取
视图
看起来您的动作功能当前没有基于您正在使用的选择器获取任何参数,因此您也需要进行更正。我假定您的意思是希望将视图发送到动作功能,并且该手势已添加到该视图中 在这种情况下,您只需从传递给动作函数的手势中获取
视图
看起来您的操作函数当前没有根据您使用的选择器获取任何参数,因此您也需要更正这些参数。您需要添加
(:)
在#选择器(didLongPressCell(:)
中,您的方法如下所示
let lpGestureRecognizer: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressCell(_:)))
func didLongPressCell(sender: UIView!) -> Void {
//Your sender here is a cell
}
你需要添加
(:)
在#选择器(didLongPressCell(:)
中,您的方法如下所示
let lpGestureRecognizer: UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressCell(_:)))
func didLongPressCell(sender: UIView!) -> Void {
//Your sender here is a cell
}
首先像这样更改
ui的选择器
语法
#selector(self.didLongPressCell(_:))
现在将此didLongPressCell
方法添加到您的viewController
func didLongPressCell(gesture: UILongPressGestureRecognizer) {
if (gesture.state == .Ended) {
let point = gesture.locationInView(self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(point)
let customCell = self.tableView.cellForRowAtIndexPath(indexPath) as! CustomCell
//This is the cell that you want.
}
}
首先像这样更改ui的选择器
语法
#selector(self.didLongPressCell(_:))
现在将此didLongPressCell
方法添加到您的viewController
func didLongPressCell(gesture: UILongPressGestureRecognizer) {
if (gesture.state == .Ended) {
let point = gesture.locationInView(self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(point)
let customCell = self.tableView.cellForRowAtIndexPath(indexPath) as! CustomCell
//This is the cell that you want.
}
}
您可以使用手势.view
属性获取长按视图
尝试以下操作:
func didLongPressCell(gesture:UILongPressGestureRecognizer) {
let cell: UITableViewCell = gesture.view as! UITableViewCell
print(cell.textLabel?.text)
//use this cell
}
您可以使用手势.view
属性获取长按视图
尝试以下操作:
func didLongPressCell(gesture:UILongPressGestureRecognizer) {
let cell: UITableViewCell = gesture.view as! UITableViewCell
print(cell.textLabel?.text)
//use this cell
}
UILongPressGestureRecognizer有一个属性“view”,它将向您显示手势附加到的视图。UILongPressGestureRecognizer有一个属性“view”,它将向您显示手势附加到的视图。