gpt4 book ai didi

ios - 尝试分配除自身以外的委托(delegate)时出现解析错误

转载 作者:行者123 更新时间:2023-11-29 01:26:07 25 4
gpt4 key购买 nike

我在尝试使用 PFLoginViewController 时遇到奇怪的错误(解析)。

PFLoginViewController类接受委托(delegate)。这是我将委派给的类(class):

class AuthenticationController: UIViewController, PFLogInViewControllerDelegate {

func logInViewController(logInController: PFLogInViewController, shouldBeginLogInWithUsername username: String, password: String) -> Bool {
return true
}
}

符合PFLogInViewControllerDelegate这正是 Parse 所期待的。这是我分配委托(delegate)并调用登录的 Controller :

class MyAccountTableViewController: UITableViewController {
@IBAction func handleLogInTap(sender: UIButton) {
let loginViewController = PFLoginViewController()
loginViewController.delegate = AuthenticationController()
self.presentViewController(loginViewController, animated: true, completion: nil)
}
}

尝试登录时,以下内容会在 PFLoginViewController.m (_loginAction) 中运行:

NSString *username = _logInView.usernameField.text ?: @"";
NSString *password = _logInView.passwordField.text ?: @"";

if (_delegateExistingMethods.shouldBeginLogIn) {
if (![_delegate logInViewController:self shouldBeginLogInWithUsername:username password:password]) {
return;
}
}

如果我po _logInView.usernameField我得到正确的回应:

<PFTextField: 0x106c1a480; baseClass = UITextField; frame = (0 252; 375 44); text = 'myusername'; clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x10b61cad0>; layer = <CALayer: 0x10ad0eb60>>

但是如果我po username设置后:

error: Couldn't materialize: couldn't get the value of variable username: variable not available
Errored out in Execute, couldn't PrepareToExecuteJITExpression

对于password也是如此.监视列表均显示为 nil .

我相信这与分配另一个类作为委托(delegate)而不是使用 self 有关。 .我可以通过制作 MyAccountTableViewController 来让它工作符合 PFLogInViewControllerDelegate然后分配 self给代表。但我需要将登录逻辑分解为一个单独的类。

我卡住了。有什么想法吗?

最佳答案

这一行的问题在于您创建了类 AuthenticationController 并且它在函数 handleLogInTap 结束时被释放。

loginViewController.delegate = AuthenticationController()

您需要在您的类 MyAccountTableViewController 中保留对它的引用,这应该是好的。

private var authentication = AuthenticationController()

@IBAction func handleLogInTap(sender: UIButton) {
let loginViewController = PFLoginViewController()
loginViewController.delegate = authentication
self.presentViewController(loginViewController, animated: true, completion: nil)
}

关于ios - 尝试分配除自身以外的委托(delegate)时出现解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33991200/

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