gpt4 book ai didi

ios - 从其他类调用 Controller 函数

转载 作者:行者123 更新时间:2023-11-28 20:01:05 25 4
gpt4 key购买 nike

我有一个问题:

我有一个当前打开的名为 Login.xib 的 Controller ,它有方法 showErrorPopup,当来自服务器的数据显示登录名或密码错误或没有互联网时应该触发该方法。

但问题是我的网络请求是在其他类文件 - DataServices.m 中处理的

问题是,如何从其他类文件触发 showErrorPopup?

最佳答案

您可以在 DataServices.m 中设置 Controller 。在 DataServices.m 中声明类型为“Login”的 un 变量,例如:

@property (nonatomic) Login *myLogin;

然后当您调用 DataServices 时:

DataServices *aDS = [[DataServices alloc] init];
aDS.myLogin = self; //if you call from Login.

然后,在您的 DataServices 函数中。

-(void)myFunction {
if (self.myLogin && [self.myLogin respondToSelector:@"afunction"]) {
[self.myLogin performselector:@"afunction"];
//...
}

希望对您有所帮助。

关于ios - 从其他类调用 Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23995681/

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