I have a tableview with custom cells, when I tap on one of my cells it shows me the next viewcontroller as it should be, but there is a delay which sometimes goes up to 5 seconds.
How can I get rid of the delay?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let person = persons[indexPath.row]
var personViewController: PersonViewController = self.storyboard?.instantiateViewControllerWithIdentifier("PersonViewController") as PersonViewController
personViewController.name = person.name
personViewController.imageName = person.image
self.presentViewController(personViewController, animated: true, completion: nil)
}
PersonViewController
import UIKit
class PersonViewController: UIViewController {
@IBOutlet weak var personImage: UIImageView!
@IBOutlet weak var overlayImage: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
var name: String?
var imageName: String?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.personImage.image = UIImage(named: imageName!)
self.overlayImage.image = UIImage(named: "image_overlay.png") //this is a filter
self.nameLabel.text = imageName
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I have the same problem and it seems that this is a bug of iOS. Solved with the following solution.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
Int64(0 * Double(NSEC_PER_SEC))),
dispatch_get_main_queue()) { () -> Void in
self.presentViewController(personViewController, animated: true,completion: nil)
}
Swift3 version:
DispatchQueue.main.async {
self.presentViewController(personViewController, animated: true,completion: nil)
}
Maybe you will call the method
[tableView deselectRowAtIndexPath:indexPath animated:NO];
before Push ViewController or Other Operation. Like
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// 1. manual call this method to deSelect Other Cell
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// 2. than do other operation
PushViewController Or Some Animation ....
}
that`s solve my problem . when i custom transition viewController for Model Style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With