gpt4 book ai didi

ios - 当我长按 UITableView Custom Header Cell 时应用程序崩溃

转载 作者:可可西里 更新时间:2023-11-01 01:39:57 26 4
gpt4 key购买 nike

我有一个简单的 UITableViewController,其中包含一组数据、员工名字和姓氏。我创建了一个自定义标题原型(prototype)单元格,其中只有一个标签来设置标题标题。

但问题是,当用户在表格的标题单元格上“长按”时,应用程序会崩溃。

在附加的屏幕截图中,当“长按”ed 时,Header0、Header1、Header3、Header4 应用程序崩溃。但是,标有红色椭圆的页眉部分是页眉的简单 UIView,但没有任何标签或任何控件。奇怪的是,如果用户“长按”这个空的标题,应用程序不会崩溃。

标题 View 的代码

override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

if ( section == 2 ){
var emptyView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 50))
return emptyView
}

let cell = tableView.dequeueReusableCellWithIdentifier("HeaderCell") as! UITableViewCell

let c = cell as! HeaderTableViewCell
c.contentView.backgroundColor = UIColor.darkGrayColor()
c.headerTextLabel.text = "Header" + toString(section)
return c.contentView
}

想知道发生了什么。我最近将 Xcode 更新到具有 Swift 1.2 的 6.3。如何解决这个问题?

非常感谢任何帮助

Sample UITableView with Custom Header cell

最佳答案

我通过删除单元格的内容 View (c.contentView) 上的手势来修复它。

 if let recognizers = c.contentView.gestureRecognizers
{
for recognizer in recognizers {
c.contentView.removeGestureRecognizer(recognizer as! UIGestureRecognizer)
}
}

关于ios - 当我长按 UITableView Custom Header Cell 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30784193/

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