【发布时间】:2015-10-30 00:36:16
【问题描述】:
我有一个带有基本单元格的简单 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
但实际上屏幕上没有显示警报。
任何可以找到解决方案的建议或指示将不胜感激。
【问题讨论】:
-
您的代码运行良好。
-
你应该用仪器检查。这段代码看起来不错。
-
实际上 UIAlertView 已被弃用。使用 UIAlertController。
-
可能是 xCode 版本 6.4 (6E35b) 的问题,但我在真实设备上也有同样的问题,不仅在模拟器中
-
谢谢,stosha,但 UIAlertView 中没有问题。任何代码都有相同的效果。
标签: ios swift uitableview uikit