gpt4 book ai didi

ios - 在 View 不在窗口层次结构中的 PFLogInViewController 上显示 *.viewController

转载 作者:行者123 更新时间:2023-11-28 06:59:15 25 4
gpt4 key购买 nike

我已经看过 StackOverFlow。似乎没有现有问题对我有帮助。

我正在使用 ParseUI 来处理用户登录功能,但在注册新用户时遇到问题。

问题:当用户去注册并点击“注册”按钮时,会出现此错误并且不会发生 segue:

<Warning: Attempt to present edus.ClassEntryViewController: 0x7f8800ceb0a0> on <PFLogInViewController: 0x7f8800c2f520> whose view is not in the window hierarchy!

我不知道如何解决这个问题。相关代码如下:

import UIKit
import Parse
import Bolts
import ParseUI
import FBSDKCoreKit
import ParseFacebookUtils


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var parseLoginHelper: ParseLoginHelper!

override init() {
super.init()

parseLoginHelper = ParseLoginHelper {[unowned self] user, error in
// Initialize the ParseLoginHelper with a callback
if let error = error {
// 1
ErrorHandling.defaultErrorHandler(error)
} else if let user = user {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//creation
let classNavEntry = storyboard.instantiateViewControllerWithIdentifier("ClassNavEntry") as! UIViewController
//presentation. PROBLEM HERE??
self.window?.rootViewController!.presentViewController(classNavEntry, animated:true, completion:nil)
}
}
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let user = PFUser.currentUser()

let startViewController: UIViewController;

if (user != nil) {
// 3
// if we have a user, set the ClassNavEntry to be the initial View Controller
let storyboard = UIStoryboard(name: "Main", bundle: nil)
//problem may arise here
startViewController =
storyboard.instantiateViewControllerWithIdentifier("ClassNavEntry") as! UINavigationController
} else {
// 4
// Otherwise set the LoginViewController to be the first
let loginViewController = PFLogInViewController()
loginViewController.fields = .UsernameAndPassword | .LogInButton | .SignUpButton | .PasswordForgotten | .Facebook
loginViewController.delegate = parseLoginHelper
loginViewController.signUpController?.delegate = parseLoginHelper
startViewController = loginViewController
}

// 5
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.window?.rootViewController = startViewController;
self.window?.makeKeyAndVisible()

更新:我知道是什么导致了问题,但仍在寻找解决方法。

问题是有两个 View Controller :loginViewController 和 SignupViewController。我在这里指定 Root View Controller 是 loginViewController:

loginViewController.delegate = parseLoginHelper
loginViewController.signUpController?.delegate = parseLoginHelper
startViewController = loginViewController
}

// 5
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
//THIS SPECIFIES ROOTVIEW TO BE LOGINVIEWCONTROLLER
self.window?.rootViewController = startViewController
self.window?.makeKeyAndVisible()

所以我也需要能够在 SignUpViewController 上调用 parseHelper...

最佳答案

将这行代码添加到您的 ParseLoginHelper 函数内,该函数对新注册 (didSignUpUser) 使用react

signUpController.dismissViewControllerAnimated(true, completion: nil)

它应该是这样的:

extension ParseLoginHelper : PFSignUpViewControllerDelegate {
func signUpViewController(signUpController: PFSignUpViewController, didSignUpUser user: PFUser) {
signUpController.dismissViewControllerAnimated(true, completion: nil)
self.callback(user, nil)
}
}

关于ios - 在 View 不在窗口层次结构中的 PFLogInViewController 上显示 *.viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32487227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com