gpt4 book ai didi

ios - 将 UITapGestureRecognizer 添加到动态添加的 View

转载 作者:行者123 更新时间:2023-11-30 14:02:28 25 4
gpt4 key购买 nike

我在将 tapRecognizers 添加到我的 View 时遇到一些问题。我向我的 UIScrollView 添加了未知数量的事件、新闻和优惠券,单击后我想打开详细 View 。但是,单击后应用程序崩溃并出现以下错误

Almhults_appen.MainActivity redirectFromHomeScreen:]: unrecognized selector sent to instance 0x7f93c2d4df20

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Almhults_appen.MainActivity redirectFromHomeScreen:]:

正如我所见,我可以利用 UITableView 并将所有 View 添加到其中。然而,如果可能的话,我个人希望避免它,但由于我是 Swift 的新手,我不相信自己的判断。

if (!event_ar.isEmpty) {
for event: Event in event_ar {

... Init EventView and add to UIScrollView

// Add tapGesture
let tapGesture: UITapGestureRecognizer = UITapGestureRecognizer(
target: self,
action: "redirectFromHomeScreen:"
)
eventView.addGestureRecognizer(tapGesture)
}
}
if (!news_ar.isEmpty) {
... Add news identically to events
}
if (!coupon_ar.isEmpty) {
... Add coupons identically to events
}

编辑添加的 Action 功能

private func redirectFromHomeScreen(sender: UITapGestureRecognizer) -> Void{
... Do stuff
}

提前致谢:)

最佳答案

根据你的崩溃报告..首先你需要声明函数

func redirectFromHomeScreen (sender : UITapGestureRecognizer){

}

声明这一点并重试

关于ios - 将 UITapGestureRecognizer 添加到动态添加的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32820478/

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