在我的应用中,UIViewController
“ProfilVC
”是UINavigationController
“nav
”的一部分。
但是在另一个场景中,我呈现“ProfilVC
”以重复使用相同的UIViewController
,但使用不同的数据。
let vc = tweetsStb.instantiateViewController(withIdentifier: "ProfilVC") as! ProfilVC
self.present(vc, animated: true, completion: nil)
在didSelectRowAt
内,我正在展示另一个UIViewController
。在这里,我需要检查self
(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
属于nav
,则此代码非常有用。
但如果self.present(vc, animated: true, completion: nil)
出现在最顶层,我需要ProfilVC
。
我需要的是这样的事情:
if(nav?.topViewController?.isKind(of: ProfilVC.self) != nil) {
nav?.present(vc, animated: true, completion: nil)
} else {
self.present(vc, animated: true, completion: nil)
}
此代码存在的问题是ProfilVC
始终是nav
的一部分。我需要检查ProfilVC
"self"
/“当前可见的”是nav
的一部分还是最顶层显示...
实现我想要的最佳方法是什么?非常感谢帮助。
PS:在ProfilVC
中提出nav
的第二个实例是不可取的,因为我ProfilVC
nav
$studentID = "1234567";
if (preg_match('/^[0-9]{7,10}$/', $studentID)) {
echo "$studentID matched!\n";
}
$familyname = "Pupkin";
if (preg_match ('/^[A-Z -]{0,20}$/i', $familyname)) {
echo "$familyname matched!";
}
需要{0,20}
。
答案 0 :(得分:5)
每个ViewController都有一个navigationController property。如果ViewController不是导航堆栈的一部分,则此属性为nil。