gpt4 book ai didi

ios - 在点击 UITableViewCell 中的 DesignableView 以进行更改时遇到问题

转载 作者:行者123 更新时间:2023-11-28 13:11:44 26 4
gpt4 key购买 nike

提前感谢您抽出时间提供帮助。

在我的 CellForRowAtIndexPath 中,我有以下行:

cell.timeView.addTarget(self, action: "ButtonDidPress:", forControlEvents: UIControlEvents.TouchUpInside)

我的选择器函数是:

func ButtonDidPress (sender: DesignableView!){
let view:DesignableView = sender
cell.timeView.shadowColor = UIColor.yellowColor()
table.reloadData()
}

我得到的错误是:

unrecognized selector sent to instance

我在想,也许人们无法将 View 作为选择器发送(我使用的术语是否正确?),但我还能如何定位该单元格中的特定 View ?

更新:

我也尝试使用 gestureRecognizer 代替:

 var tap = UIGestureRecognizer(target: self, action: Selector( "viewDidTap:"))
cell.timeView.addGestureRecognizer(tap)

func viewDidTap (sender: DesignableView!){

但我在这里遇到了同样的错误。

谢谢!

最佳答案

您的代码中发生了一些奇怪的事情。似乎您想在用户触摸时更改 timeViewshadowColor 属性,对吗?

两种可能的解决方案是:

  1. (在我看来,这个更好)将 DesignableView 更改为继承自 UIButton。然后你可以设置:timeView.addTarget(self, action: "ButtonDidPress:", forControlEvents: .TouchUpInside)。确保为每个单元格只设置一次。否则,您将一键接听多个电话。

  2. 使用 UITapGestureRecognizer,但您应该将其放在 UITableViewCell 子类中,而不是 View Controller 。此外,viewDidTap 中的发送者不是 View 本身,而是识别器。所以这个方法将是这样的:

    func viewDidTap(sender: UITapGestureRecognizer) {

    let location = sender.locationInView(sender.view)

    if timeView.hitTest(location, withEvent: nil) == timeView {

    timeView.shadowColor = UIColor.yellowColor()
    // table.reloadData() - you don't need to reload the table
    }
    }

关于ios - 在点击 UITableViewCell 中的 DesignableView 以进行更改时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31028446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com