【发布时间】:2018-05-31 14:14:49
【问题描述】:
我有一个带有自定义 UITableViewCell 的 UITableView,但我遇到了一个奇怪的问题,如果我想调用 didSelectRowAt 函数,我需要按下单元格(并保持按下状态)2 秒钟。
我尝试使用 didHighlightRowAt 函数,这需要更少的时间(1 秒),但我仍然需要按下并等待一秒钟,如果我不这样做,什么也不会发生。
我的 cellForRowAt 函数是以下一个(我不知道这是否相关?):
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = StationSearchCellView(style: .default, reuseIdentifier: "cell", station: self.tableSearchesData[indexPath.section])
cell.selectionStyle = .none
return cell
}
我的自定义单元格是:
class StationSearchCellView : UITableViewCell {
var stationName : String? init (
style : UITableViewCellStyle,
reuseIdentifier : String?,
station : String
)
{
super.init (style: style, reuseIdentifier: reuseIdentifier)
self.stationName = station let frameHeight = FDUtils.shared.heightRelativeToLayout (heightInPixels: 60)
let iconSize = FDUtils.shared.widthRelativeToLayout (widthInPixels: 16)
let marginWidth = FDUtils.shared.widthRelativeToLayout (widthInPixels: 20)
// separator
let separator = UIView (
frame : CGRect (x: 0, y: 0-0.5, width: self.frame.width, height: 1)
)
separator.backgroundColor = FDColors.gray707070.withAlphaComponent (0.50)
// Label Station
let labelStation = UILabel (
frame : CGRect (
x : 0,
y : 0,
width : FDUtils.shared.elementsWidth - iconSize - marginWidth,
height : frameHeight
)
)
labelStation.text = station labelStation.setBlack_Left_Regular16 ()
// Image fleche
let searchIcon = UIImageView (
frame : CGRect (
x : labelStation.frame.width,
y : labelStation.frame.height / 2 - iconSize / 2,
width : iconSize,
height : iconSize
)
)
searchIcon.image = UIImage (named: "blue_select_icon")
self.addSubview (separator)
self.addSubview (labelStation)
self.addSubview (searchIcon)
}
required init? (coder aDecoder: NSCoder)
{
fatalError ("init(coder:) has not been implemented")
}
}
有什么想法吗?
谢谢
【问题讨论】:
-
我敢打赌,您的视图上有一个
UITapGestureRecognisor,它需要在手势传递到下面的单元格之前失败。 -
@Scriptable 就是这样!谢谢 !但是我怎样才能让我的 tapGesture 保持在视图上呢? (当用户完成编辑时,我用它来隐藏键盘)
-
有一些常用的方法,我会发一个例子作为答案。您也可以禁用手势,除非键盘显示,然后在隐藏时启用它
-
您确实应该将单元格从表格视图中出列。不像你正在做的那样初始化单元格。
标签: ios swift uitableview