【发布时间】:2017-02-28 15:33:09
【问题描述】:
我使用 UITableViewCell 控制器在表格中配置动态单元格,并且我想在单击特定轻按手势时执行转场
class PostCell: UITableViewCell {
@IBOutlet var actionComments: UIImageView!
var post: FeedPost!
let postID: String = ""
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(likeTapped))
tapGesture.numberOfTapsRequired = 1
actionLike.addGestureRecognizer(tapGesture)
actionLike.isUserInteractionEnabled = true
let commentGesture = UITapGestureRecognizer(target: self, action: #selector(goToComments))
commentGesture.numberOfTapsRequired = 1
commentGesture.delegate = self
actionComments.addGestureRecognizer(commentGesture)
actionComments.isUserInteractionEnabled = true
}
func goToComments(sender: UITapGestureRecognizer) {
}
}
这是我的 PostCell 类(为了这篇文章,我刚刚删除了一些额外的代码)这是我的表格视图,这是我的 newsfeedvc
class NewsFeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var posts = [FeedPost]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let post = posts[indexPath.row]
if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? PostCell {
cell.configureCell(post: post)
return cell
} else {
return PostCell()
}
}
}
我已经用 identifer 设置了 segue,但我不能在我的 postcell 类的 goToComments 函数中使用 performegue?
【问题讨论】:
-
是什么阻止您在
goToComments(sender:)中使用performSegue?您是否在情节提要中添加了转场?应用程序会崩溃吗?你得到什么错误信息?人们需要更多细节才能理解问题。 -
@RoboticCat 如果我将
performSegue(withIdentifier: "goToComments", sender: nil)添加到goToComments 我得到Use on unresolved identifier -
什么未解析的标识符 - 您缺少错误消息的一部分,该错误消息应指示什么不在范围内。这都应该添加到您的问题中。另外,您是否在 Stack Overflow 上搜索过具有相同错误消息的问题?有很多解决方案;你排除了什么?
-
@RoboticCat 'performSegue' 是未解析的标识符。我已经尝试寻找解决方案,它们包括覆盖准备转场但是,我试图添加手势的图像链接到
postcell: uitableviewcell类,所以我不能在 newsfeedvc 中再次声明它以执行转场那里
标签: ios swift uitableview swift3 segue