- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在以编程方式完全从头开始创建我的应用程序,没有使用 Storyboard 。
我的应用程序与 Firebase 集成,并使用 Facebook 登录。
我的设置相当简单:
- Launch the app -> takes you to the first VC called
WelcomeViewController
.- There is a check that happens in the
viewDidLoad
method to see if a user is already signed in and exists. If there is, it sends you straight to the second VC calledFilmsViewController
- The
FilmsViewController
is a collectionViewController that displays films. The user can press a film, and it takes them to more information about that film.
(作为引用,我已经在我的应用程序中登录了 Facebook)
我有一个当前问题,当上面的第 2 步发生时,它会转换到 FilmsViewController
,但它会转换 2 或 3 次。所以你看到新的 VC 出现了 2 或 3 次,然后内容加载了。如果您按下导航栏中的 Back
按钮,它会带您返回到它加载的 2 或 3 个 viewController,然后再返回到 WelcomeViewController
。
我的观点如下。
在 AppDelegate.swift
中:
var window: UIWindow?
var navController: UINavigationController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
navController = UINavigationController()
let firstViewController: WelcomeViewController = WelcomeViewController()
self.navController!.pushViewController(firstViewController, animated: true)
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navController
window?.makeKeyAndVisible()
return true
}
在 viewDidLoad
的 WelcomeViewController
中:
FIRAuth.auth()?.addStateDidChangeListener { auth, user in
if let user = user {
// User is signed in.
// Direct the user to the home screen
let toFilmListVC = FilmsViewController(collectionViewLayout: UICollectionViewFlowLayout())
self.navigationController?.pushViewController(toFilmListVC, animated: true)
} else { ...
}
}
我找了很多解决方案 - 但一无所获。我只找到一篇关于这个问题的帖子,有人说解决方案是更改该 Controller 的类名,我已经这样做了,但没有任何改变。
谁能帮我解决这个问题?谢谢。
最佳答案
addStateDidChangeListener
可能被调用了多次。
你应该修改它来检查一个 FilmsViewController
是否已经被推送,以防止推送另一个:
FIRAuth.auth()?.addStateDidChangeListener { auth, user in
if let user = user {
// User is signed in.
// Direct the user to the home screen
// Only push one FilmsViewController onto the navigation stack!
var shouldPush = true
if let navigationController = self.navigationController {
for viewController in navigationController.viewControllers {
if viewController is FilmsViewController {
shouldPush = false
}
}
}
if shouldPush {
let toFilmListVC = FilmsViewController(collectionViewLayout: UICollectionViewFlowLayout())
self.navigationController?.pushViewController(toFilmListVC, animated: true)
}
} else { ...
}
}
关于ios - 在 swift 中以编程方式创建 navigationController 时,ViewController 出现多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39669682/
您好,所以我有这个 storyboard 结构 我在 ViewController B 中有一个 button 我需要那个 button 指向底部NavigationController 其中有 Vi
我的基于 Storyboard 的应用具有以下结构: NavigationController (NavCa) —> CollectionViewController (VCa) —> 模态呈现 —>
我可以用 MyFirstAppDelegate *delegate = (MyFirstAppDelegate *)[[UIApplication sharedApplication] delegat
我正在使用以下策略构建一个基于窗口的(所有 UI 都以编程方式连接,没有 IB)MonoTouch 应用程序: 伪代码: Note: I'm not calling base.ViewDidLoad
我发现了困难的方法 navigationController.navigationBarHidden = NO; 和 navigationController.navigationBar.hidden
这两种说法有什么区别。为了隐藏导航栏,我使用以下语句之一在 viewWillAppear 方法中隐藏导航栏,如下所示: -(void)viewWillAppear:(BOOL)animated {
我已经发布了这个问题,但这次我发布了代码。所以我有一个uiviewController,在这个viewController的viewDidLoad中我隐藏了navigationController的b
我想在横向显示另一个没有选项卡栏的 View 。所以我创建了一个新 View ,只更改 self.view 和 self.hidesBottomBarWhenPushed = YES; 但这对我不起作
当我将新的 ViewController 推送到导航 Controller 堆栈上时,“后退”按钮是前一个 Controller 的标题。 如何将后退按钮中的文本更改为“后退”而不是默认的最后一个 C
我在我的应用程序中设置了一个 subview “弹出窗口”,如果用户点击 subview 弹出窗口上的按钮,我想显示一个 navController。到目前为止,我已经设置了按钮,但是如果我点击按钮,
我有两个问题: 问题 1:我正在尝试更改导航后退按钮,我正在从父 ViewController 执行此操作: -(void)prepareForSegue:(UIStoryboardSegue *)s
我有一个 UINavigationController,它的根 Controller (UITableViewController) 和一个 UIViewController 的实例,当我单击导航 C
我正在尝试制作我的第一个基于表格的应用程序。但是它不会改变导航栏上标题的颜色。 我试过这段代码,但它似乎不起作用: this.NavigationController.NavigationItem.T
问题如图所示。我怎样才能从 viewcontroller C 返回到 A。方法 popViewController Animated 不起作用。 最佳答案 您的 Controller 层次结构存在问题
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit th
我在使用 Navigation Controller 转到我的详细 View 时遇到问题。 我正在使用 tableview 来显示一些练习,当你点击练习时,你会进入详细 View ,嵌入在导航 Con
我试图通过允许用户添加算命应用程序的新结果来理解演示 View Controller 。当用户点击导航栏右上角的“添加新结果”时,会弹出一个新的 View Controller ,用户可以在此处输入新
当我点击页面底部的灰色按钮时,我想使用 popToRootController 从最后一页返回到第一页。 我不明白如何同时对两个导航 Controller 进行操作。我为最后两页使用了一个库。 Sid
我有一个 navigationController 嵌入在我的 Root View 和 subview 中,并且在我的一个 subview 中有: @IBAction func button(send
是否可以将后退按钮的图标从箭头更改为其他图标? (在导航栏中) 我在storyboard的preferences里没找到解决方案 最佳答案 如果您的部署目标至少是 iOS 7,您可以使用 backIn
我是一名优秀的程序员,十分优秀!