gpt4 book ai didi

ios - didSelectRowAtIndexPath 之后的延迟

转载 作者:搜寻专家 更新时间:2023-10-30 21:47:55 25 4
gpt4 key购买 nike

我有一个带有自定义单元格的表格 View ,当我点击我的一个单元格时,它会按原样显示下一个 View Controller ,但会有延迟,有时会长达 5 秒。

我怎样才能摆脱延迟?

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)
}

人物 View Controller

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.
}

最佳答案

我有同样的问题,看来这是iOS的一个错误。使用以下解决方案解决。

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 版本:

DispatchQueue.main.async {
self.presentViewController(personViewController, animated: true,completion: nil)
}

关于ios - didSelectRowAtIndexPath 之后的延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28307811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com