【发布时间】:2019-06-13 11:20:23
【问题描述】:
当我尝试从 TabBarController 的第 4 个选项卡(嵌入在 NavigationViewController 中的 TableViewController)模态显示视图控制器时,它会连续显示两次。
实际方法present(_:animated:completion:) 连续调用两次,而它应该只发生一次。
这就是我从UITableViewController 调用方法的方式。现在因为我收到“尝试呈现其视图不在窗口层次结构中的 vc”警告,所以我尝试了这种解决方法,但我不再收到该警告,但现在我遇到了这个问题。
((UIApplication.shared.keyWindow?.rootViewController as? MainTabBarViewController)?.selectedViewController as? NavigationPodesavanjaViewController)?.visibleViewController?.present(Egg, animated: true, completion: nil)
这是视图控制器中呈现的所有内容。它现在就像一个虚拟内容,带有一个后退按钮:
import UIKit
class EasterEggViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = ConstantsClass.ljubicastaBoja
let imageView = UIImageView(image: UIImage(named: "operator-ikonica"))
view.addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
imageView.frame.size = CGSize(width: 250, height: 250)
let backButton = UIButton()
view.addSubview(backButton)
backButton.setTitle("Nazad", for: .normal)
backButton.titleLabel?.textColor = .white
backButton.frame = CGRect(x: 50, y: 50, width: 100, height: 20)
backButton.titleLabel?.adjustsFontSizeToFitWidth = true
backButton.addTarget(self, action: #selector(dismissAction), for: .touchUpInside)
}
@objc func dismissAction() {
dismiss(animated: true, completion: nil)
}
}
在长按手势的处理程序中调用 present 方法。 //注意:当我将长按更改为点击时,它可以正常工作,当我将其更改回来时,它再次出现两次。
这是来自 viewDidLoad 的部分代码:
let longPressEgg = UILongPressGestureRecognizer()
longPressEgg.addTarget(self, action: #selector(easterEggScreenPresent))
easterEgg.addGestureRecognizer(longPressEgg)
这是处理程序:
@objc func easterEggScreenPresent(){
let Egg = EasterEggViewController()
((UIApplication.shared.keyWindow?.rootViewController as? MainTabBarViewController)?.selectedViewController as? NavigationPodesavanjaViewController)?.visibleViewController?.present(Egg, animated: true, completion: nil)
}
【问题讨论】:
-
你确定在其他地方没有第二次出席电话吗?
-
这是 tabBar 的根 viewController 吗?或者它是一个在推送后出现在第 4 个选项卡上的控制器?
-
@AndréSlotta 是的,同样的方法,在同一行,被调用了两次。
-
@GaloTorresSevilla 这在 TabBarViewController 的第 4 个选项卡上调用。
-
我明白这一点。但这不是我的意思。您确定在您的代码的其他部分没有其他方法调用当前方法吗?顺便说一句,
Egg是什么?
标签: ios swift uitableview uiview