私のアプリケーションではUIViewController
"ProfilVC
"はUINavigationController
"nav
"の一部です。現在のUIViewControllerがUINavigationControllerの一部であるかどうかを確認する方法
しかし、別のシーンでは、私ははUIViewController
同じですが、異なるデータとを再利用する「ProfilVC
」を提示しています。 didSelectRowAt
内
let vc = tweetsStb.instantiateViewController(withIdentifier: "ProfilVC") as! ProfilVC
self.present(vc, animated: true, completion: nil)
、私は別のUIViewController
を提示しています。そして、ここで私はself
(ProfilVC
)が現在nav
の一部であるか、または上に提示されているかどうかを確認する必要があります。 ProfilVC
がnav
の一部である場合
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = tweetsStb.instantiateViewController(withIdentifier: "TweetCommentsVC") as! TweetCommentsVC
let post = tweets[(indexPath as NSIndexPath).section]
let cell = tableView.cellForRow(at: indexPath) as! TweetPostCell
vc.commentCounterString = cell.commentLabel.text!
vc.post = post
vc.avatare = avatare
nav?.present(vc, animated: true, completion: nil)
}
このコードは完璧に動作します。
ProfilVC
が表示されている場合はself.present(vc, animated: true, completion: nil)
が必要です。 ProfilVC
は常にnav
の一部であることを、
if(nav?.topViewController?.isKind(of: ProfilVC.self) != nil) {
nav?.present(vc, animated: true, completion: nil)
} else {
self.present(vc, animated: true, completion: nil)
}
このコードに問題がある:私は必要なもの
はこのようなものです。私は自分の望むを達成するための最良の方法は何
... ProfilVC
"self"
として/「現在の見える1」はnav
または上に提示の一部であるかどうかを確認する必要がありますか?ヘルプは非常に感謝しています。
PS:私はnav
のこのcase to overlapp the UINavigationBarでProfilVC
を必要とするのでnav
内ProfilVC
の2番目のインスタンスを提示にはオプションではありません。
少なくともコメントしてください? –