我有一个带有基本单元格的简单 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
与
cell.selectionStyle = UITableViewCellSelectionStyle.Default
彻底解决问题。之后每次点击行都会立即显示结果。
关于ios - UITableViewCell 对选择的响应非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31862935/