我遇到了类似的问题,但没有像我目前的设置,因此很难找到修复。
我有一个自定义UIViewController
扩展程序,其中包含两个以编程方式显示和解散VC的函数(参见下文)。
extension UIViewController {
//present VC fromRight
func presentDetail(_ viewControllerToPresent: UIViewController){
//constant to hold animation
let transition = CATransition()
transition.duration = 0.3 //seconds
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
self.view.window?.layer.add(transition, forKey: kCATransition)
present(viewControllerToPresent, animated: false, completion: nil)
}//end func
//dismiss VC fromLeft
func dismissDetail(){
//constant to hold animation
let transition = CATransition()
transition.duration = 0.3 //seconds
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
self.view.window?.layer.add(transition, forKey: kCATransition)
dismiss(animated: false, completion: nil)
}//end func
}
我有一个VenueListVC
(主要VC),其中UITableView
,我的didSelectRowAt
功能位于下方(使用上面的自定义扩展程序)VenueDetailsVC
(次要) VC)。
我的问题是,当选择一个单元格时,主VC(VenueListVC)会在模态呈现辅助VC(VenueDetailsVC)之前加载两次。我在这两个VC之间没有其他细分。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let venueDetailsVC = storyboard?.instantiateViewController(withIdentifier: "VenueDetailsVC") as? VenueDetailsVC else { return } //create an instance of VenueDetailsVC
presentDetail(venueDetailsVC)//present Group Feed VC using custom extension
}