Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell在选择时响应非常慢_Ios_Swift_Uitableview_Uikit - Fatal编程技术网

Ios UITableViewCell在选择时响应非常慢

Ios UITableViewCell在选择时响应非常慢,ios,swift,uitableview,uikit,Ios,Swift,Uitableview,Uikit,我有一个简单的UITableViewController和基本单元。 didSelectRowAtIndexPath做简单的工作-只需创建UIAlertView并显示它 问题是当我点击一行时,有时会立即看到警报,有时几秒钟后(最多10秒钟) 代码是 override func viewDidLoad() { super.viewDidLoad() tableView.dataSource = self tableView.delegate = self } overr

我有一个简单的UITableViewController和基本单元。 didSelectRowAtIndexPath做简单的工作-只需创建UIAlertView并显示它

问题是当我点击一行时,有时会立即看到警报,有时几秒钟后(最多10秒钟)

代码是

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.dataSource = self
    tableView.delegate = self
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as! UITableViewCell
    cell.selectionStyle = UITableViewCellSelectionStyle.None
    // Configure the cell...
    cell.textLabel?.text = "\(indexPath.row)"
    return cell
}


override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    NSLog("row clicked at index \(indexPath.row)")
    let alert = UIAlertView(title: "Test", message: "Test message", delegate: self, cancelButtonTitle: "Done")
    alert.show()
    NSLog("alert showed")
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 4
}
在日志中我看到了

2015-08-06 20:51:54.591 experimental[10323:8602172] row clicked at index 2
2015-08-06 20:51:54.595 experimental[10323:8602172] alert showed
2015-08-06 20:52:00.901 experimental[10323:8602172] row clicked at index 3
2015-08-06 20:52:00.905 experimental[10323:8602172] alert showed
但实际上,警报不会显示在屏幕上


如有任何建议或建议,请提供解决方案

这个解决方案非常奇怪

替换

cell.selectionStyle = UITableViewCellSelectionStyle.None


彻底解决问题。之后,每单击一行,就会立即显示结果。

我遇到了完全相同的问题,肯定是一个bug。在我的例子中,它在加载视图之前额外添加了150毫秒

我有一个定制的桌子单元

cell.selectionStyle = UITableViewCellSelectionStyle.None
改成

cell.selectionStyle = UITableViewCellSelectionStyle.Default

修复了这个问题…

我发现如果单元格上有图像,使用手势比选择代理要好

所以


将其放入DispatchQueue.main.async函数中

DispatchQueue.main.async{

让alert=UIAlertView(标题:“测试”,消息:“测试消息”,
委托:自我,取消按钮:“完成”)
alert.show()
NSLog(“显示警报”)
}

replace cell.selectionStyle=UITableViewCellSelectionStyle.None

cell.selectionStyle=UITableViewCellSelectionStyle.Default

如果希望
selectionStyle
为无,应将
alertView
方法添加到
dispatch\u async(dispatch\u get\u main\u queue(),^{…})

或者将
选择样式设置为默认值。

在我的情况下,我需要选择样式
。无
,因为我使用自定义单元格。因此,我必须使用
didhightrowat
didhightrowat
。使用
.default
时,无法处理这些事件

对我来说,
DispatchQueue.main.async{}
成功了

尝试设置:

delaysContentTouches = false

你的代码运行正常。你应该用仪器检查一下。这段代码看起来不错。实际上UIAlertView已被弃用。使用UIAlertController。可能是xCode版本6.4(6E35b)的问题,但我在实际设备上也有同样的问题,不仅在SimulatorTanks、stosha中,而且在UIAlertView中也没有。任何代码都有山姆效应,真的很奇怪。我使用UITableViewCellSelectionStyleBlue,并且有同样的问题。更改为UITableViewCellSelectionStyle.Default对我有效。真奇怪!这对我也有用,谢谢你,伙计。有什么想法吗?如果我们必须摆脱选择风格,我们需要做什么?这太荒谬了。有人知道为什么吗?天哪!因为这个我疯了。。。我在两个视图控制器之间进行了自定义转换,我认为我的代码是导致转换缓慢的原因。谢谢!
iv.userInteractionEnabled = YES;

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];

tap.numberOfTapsRequired = 1;
[iv addGestureRecognizer:tap];
delaysContentTouches = false