【发布时间】:2016-05-04 07:37:13
【问题描述】:
我一直在使用sendAction 方法和nil target 将操作从Cells(UITableViewCell/UICollectionViewCell) 传递到ViewControllers,而不是实现委托。
从 Swift 2.2 开始,选择器的语法已经更新,我收到了一些警告。新的#selector 语法坚持指定selectorname 后跟classname。如果我提到类名,那么将目标设置为 nil 没有任何意义。
有什么解决方法吗?
class RedeemCell: UICollectionViewCell {
@IBAction func redeemAction(sender: AnyObject) {
UIApplication.sharedApplication().sendAction("updateCartWithTotalAmountPayableWithDiscount:", to: nil, from: self, forEvent: nil)
}
}
class CartVC: UIViewController {
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell?
cell = collectionView.dequeueReusableCellWithReuseIdentifier("redeempoints", forIndexPath: indexPath)
return cell!;
}
func updateCartWithTotalAmountPayableWithDiscount(sender: AnyObject) {
print("this will be called as the action movies through responderchain and encounters this method");
}
}
【问题讨论】:
-
你能分享一下代码来解释你到目前为止是如何使用它的吗?
-
@rptwsthi 用代码更新了问题
-
是的,我刚刚检查过了,不幸的是我没有解决方法。可能有人来救援。祝你好运。
标签: ios objective-c swift swift2.2