Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell very slow response on select

I have a simple UITableViewController with basic cell. didSelectRowAtIndexPath do simple job - just make UIAlertView and show it.

The problem is when I tap on a row sometimes I see alert immediately, sometimes after few seconds (up to 10 seconds).

The code is

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
}

In log I see

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

but actually alert not shows on the screen.

Any suggestions or pointings where to find a solution would be appreciated.

like image 697
Maks Avatar asked Aug 06 '15 18:08

Maks


1 Answers

The solution is very weird

replacing

cell.selectionStyle = UITableViewCellSelectionStyle.None

with

cell.selectionStyle = UITableViewCellSelectionStyle.Default

completely solve the problem. After that every click on row will show result immediately.

like image 80
Maks Avatar answered Oct 11 '22 13:10

Maks